Ayuda con Query

07/01/2010 - 01:02 por Gabrielg | Informe spam
Hola a todos
Tengo este query:
SELECT
dbo.JDT1.Account,
Balance_001 = CASE
when ((dbo.JDT1.Account like '1%' or dbo.JDT1.Account like '2%')
AND dbo.JDT1.RefDate between '01/01/09' AND '31/12/09')
then SUM(dbo.JDT1.SYSDeb - dbo.JDT1.SYSCred)
when ((dbo.JDT1.Account not like '1%'
and dbo.JDT1.Account not like '2%')
AND dbo.JDT1.RefDate <= '31/12/09')
then SUM(dbo.JDT1.SYSDeb - dbo.JDT1.SYSCred)
ELSE '0' END
FROM dbo.JDT1
WHERE dbo.JDT1.TransType <> '-3'
GROUP BY dbo.JDT1.Account, dbo.JDT1.RefDate

El tema es que yo no quiero agrupar segun el Campo Refdate, solo lo
quiero agrupar por Account.
Si lo saco me da error.
Como puedo reformular el query para obtener lo que necesito (GROUP BY
dbo.JDT1.Account)
 

Leer las respuestas

#1 Alejandro Mesa
07/01/2010 - 04:24 | Informe spam
Trata poniendo la expresion CASE dentro de la funcion de agrupacion.

SELECT
dbo.JDT1.Account,
Balance_001 = SUM(
CASE
WHEN (
(dbo.JDT1.Account like '1%' or dbo.JDT1.Account like '2%')
AND dbo.JDT1.RefDate between '01/01/09' AND '31/12/09') THEN
(dbo.JDT1.SYSDeb - dbo.JDT1.SYSCred)
WHEN (
(dbo.JDT1.Account not like '1%' and dbo.JDT1.Account not like '2%')
AND dbo.JDT1.RefDate <= '31/12/09') THEN (dbo.JDT1.SYSDeb -
dbo.JDT1.SYSCred)
ELSE 0
END)
FROM dbo.JDT1
WHERE dbo.JDT1.TransType <> '-3'
GROUP BY dbo.JDT1.Account;


AMB

"Gabrielg" wrote:

Hola a todos
Tengo este query:
SELECT
dbo.JDT1.Account,
Balance_001 = CASE
when ((dbo.JDT1.Account like '1%' or dbo.JDT1.Account like '2%')
AND dbo.JDT1.RefDate between '01/01/09' AND '31/12/09')
then SUM(dbo.JDT1.SYSDeb - dbo.JDT1.SYSCred)
when ((dbo.JDT1.Account not like '1%'
and dbo.JDT1.Account not like '2%')
AND dbo.JDT1.RefDate <= '31/12/09')
then SUM(dbo.JDT1.SYSDeb - dbo.JDT1.SYSCred)
ELSE '0' END
FROM dbo.JDT1
WHERE dbo.JDT1.TransType <> '-3'
GROUP BY dbo.JDT1.Account, dbo.JDT1.RefDate

El tema es que yo no quiero agrupar segun el Campo Refdate, solo lo
quiero agrupar por Account.
Si lo saco me da error.
Como puedo reformular el query para obtener lo que necesito (GROUP BY
dbo.JDT1.Account)
.

Preguntas similares