Ejercicios con Case When y Procedimientos Almacenado

Ejercicios con Case When y Procedimientos Almacenado - BASE...

Info icon This preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon
B ASE DE D ATOS II Melvin Ramirez Ejercicios de Case When resueltos en procedimientos almacenados
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
C ASE W HEN CASE [expression] WHEN [value | Boolean expression] THEN [return value] [ELSE [return value]] END La [expression] es opcional y contiene el nombre de columna o de variable. Ejemplo : SELECT CASE Grado WHEN 1 THEN ‘ Primero ’ WHEN 2 THEN 'Segundo’ WHEN 3 THEN ‘ Tercero ’ ELSE ‘ Otros END
Image of page 2
C ASE W HEN Declare @Grado int Set @Grado = 2 select Case @Grado When 1 then 'Primero' When 2 then 'Segundo' When 3 then 'Tercero' Else 'Otros' End as Descripcion Select Case When @Grado = 1 then 'Primero' When @Grado = 2 then 'Segundo' When @Grado = 3 then 'Tercero' Else 'Otros' End as Descripcion
Image of page 3

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
C ASE W HEN
Image of page 4
C ASE W HEN Los datos de un columna deben ser compatibles, cuando utilizamos CASE WHEN para presentar diferentes resultados, los resultados deben ser compatibles
Image of page 5

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
E JERCICIO DE C LASE C ASE W HEN Y S UB - C ONSULTA Ventas Totales por Trimestre Año 1997 Empleados I Trimestre II Trimestre III Trimestre IV Trimestre Total Solo debe presentar una fila por empleado, con la información solicitada Las ventas deben ser calculadas de la información de pedidos, siendo el producto de cantidad * precio unidad
Image of page 6
V ENTAS TRIMESTRALES C ASE W HEN
Image of page 7

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
--Resuelto utilizando CASE WHEN select FirstName + ' ' + LastName as NombreCompleto , sum ( case when MONTH ( ors . OrderDate ) < 4 then ord . Quantity * ord . UnitPrice else 0 end ) as Trimestre_I , sum ( case when MONTH ( ors . OrderDate ) between 4 and 6 then ord . Quantity * ord . UnitPrice else 0 end ) as Trimestre_II , sum ( case when MONTH ( ors . OrderDate ) between 7 and 9 then ord .
Image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern