Ayuda con Query (CASE)

26/01/2010 - 02:21 por Gabrielg | Informe spam
Hola amigos,
Me podrian dar una mano que este query
Obtengo error por no agrupar segun Account (cosa que no quiero)

Gracias

SELECT
Project = case when dbo.JDT1.Project IS NULL then '999'
when dbo.JDT1.Account = '10006141' AND
dbo.JDT1.Project = '031' then '777'
when dbo.JDT1.Account = '10006535' AND
dbo.JDT1.Project = '031' then '888'
ELSE dbo.JDT1.Project END,
SUM (dbo.JDT1.Debit - dbo.JDT1.Credit) Balance_001,
FROM dbo.JDT1
GROUP BY Project
 

Leer las respuestas

#1 Alejandro Mesa
26/01/2010 - 15:07 | Informe spam
Gabrielg,

1 - Usa un alias nuevo para el resultado de la funcion CASE.
2 - Usa la funcion CASE en la clausula GROUP BY.

SELECT
Nuevo_Project = case when dbo.JDT1.Project IS NULL then '999'
when dbo.JDT1.Account = '10006141' AND
dbo.JDT1.Project = '031' then '777'
when dbo.JDT1.Account = '10006535' AND
dbo.JDT1.Project = '031' then '888'
ELSE dbo.JDT1.Project END,
SUM (dbo.JDT1.Debit - dbo.JDT1.Credit) Balance_001,
FROM dbo.JDT1
GROUP BY case when dbo.JDT1.Project IS NULL then '999'
when dbo.JDT1.Account = '10006141' AND
dbo.JDT1.Project = '031' then '777'
when dbo.JDT1.Account = '10006535' AND
dbo.JDT1.Project = '031' then '888'
ELSE dbo.JDT1.Project END;
GO


AMB




"Gabrielg" wrote:

Hola amigos,
Me podrian dar una mano que este query
Obtengo error por no agrupar segun Account (cosa que no quiero)

Gracias

SELECT
Project = case when dbo.JDT1.Project IS NULL then '999'
when dbo.JDT1.Account = '10006141' AND
dbo.JDT1.Project = '031' then '777'
when dbo.JDT1.Account = '10006535' AND
dbo.JDT1.Project = '031' then '888'
ELSE dbo.JDT1.Project END,
SUM (dbo.JDT1.Debit - dbo.JDT1.Credit) Balance_001,
FROM dbo.JDT1
GROUP BY Project
.

Preguntas similares