Case

11/03/2009 - 22:17 por Alexander Cadavid | Informe spam
Buenas Tardes.

Tengo esta consulta.

Select strcodter As Cedula,
Sum(Case when (strcamgen) = '200810' Then Total Else 0 End) As '200810',
Sum(Case when (strcamgen) = '200811' Then Total Else 0 End) As '200811',
Sum(Case when (strcamgen) = '200812' Then Total Else 0 End) As '200812',
Sum(Case when (strcamgen) = '200813' Then Total Else 0 End) As '200813',
Sum(Case when (strcamgen) = '200814' Then Total Else 0 End) As '200814',
Sum(Case when (strcamgen) = '200815' Then Total Else 0 End) As '200815',
Sum(Case when (strcamgen) = '200816' Then Total Else 0 End) As '200816',
Sum(Case when (strcamgen) = '200817' Then Total Else 0 End) As '200817',
Sum(Case when (strcamgen) = '200818' Then Total Else 0 End) As '200818',
Sum(Case when (strcamgen) = '200901' Then Total Else 0 End) As '200901',
Sum(Case when (strcamgen) = '200902' Then Total Else 0 End) As '200902',
Sum(Case when (strcamgen) = '200903' Then Total Else 0 End) As '200903',
Sum(Case when (strcamgen) = '200904' Then Total Else 0 End) As '200904',
0 As Totales
From #Ind
group by strcodter
order by 1


Y el campo totales tengo que sumar los totales de cada campaña y organizarlo
en forma descendente por totales.
como hago.
 

Leer las respuestas

#1 Jose Mariano Alvarez
11/03/2009 - 23:37 | Informe spam
Cual es la campaña?
Podrias indicar que quieres decir con "Y el campo totales tengo que sumar
los totales ".
Que significa "organizarlo en forma descendente por totales", cual es la
columna de totales?


Saludos


Ing. Jose Mariano Alvarez
http://blog.josemarianoalvarez.com/
Microsoft MVP
SQLTotal Consulting

(Cambia los ceros por O y saca lo que sobra)

Este mensaje se proporciona tal como es, SIN GARANTIAS de ninguna clase. Por
favor tratar de indicar la versión de SQL y Service Pack. La inclusión de
(CREATE, INSERTS, etc.) para poder reproducir el problema también ayuda.










"Alexander Cadavid" wrote in message
news:
Buenas Tardes.

Tengo esta consulta.

Select strcodter As Cedula,
Sum(Case when (strcamgen) = '200810' Then Total Else 0 End) As '200810',
Sum(Case when (strcamgen) = '200811' Then Total Else 0 End) As '200811',
Sum(Case when (strcamgen) = '200812' Then Total Else 0 End) As '200812',
Sum(Case when (strcamgen) = '200813' Then Total Else 0 End) As '200813',
Sum(Case when (strcamgen) = '200814' Then Total Else 0 End) As '200814',
Sum(Case when (strcamgen) = '200815' Then Total Else 0 End) As '200815',
Sum(Case when (strcamgen) = '200816' Then Total Else 0 End) As '200816',
Sum(Case when (strcamgen) = '200817' Then Total Else 0 End) As '200817',
Sum(Case when (strcamgen) = '200818' Then Total Else 0 End) As '200818',
Sum(Case when (strcamgen) = '200901' Then Total Else 0 End) As '200901',
Sum(Case when (strcamgen) = '200902' Then Total Else 0 End) As '200902',
Sum(Case when (strcamgen) = '200903' Then Total Else 0 End) As '200903',
Sum(Case when (strcamgen) = '200904' Then Total Else 0 End) As '200904',
0 As Totales
From #Ind
group by strcodter
order by 1


Y el campo totales tengo que sumar los totales de cada campaña y
organizarlo
en forma descendente por totales.
como hago.


Preguntas similares