Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Other Forums
 Other Topics
 Case Statements in MS query

Author  Topic 

Elaussie09
Starting Member

3 Posts

Posted - 2008-08-08 : 06:35:31
Hi, I have this statemnt in SQL and i wanted to convert it to MS Query. I was wondering whether one of you could possibly help.

_____________________________________________________________________

SELECT AACT.FormatCode, AACT.AccountName,
Sum(Case When OJDT.RefDate <= '2008-01-31' Then (AJD1.Debit-AJD1.Credit) End) As Month1,
Sum(Case When OJDT.RefDate <= '2008-02-29' Then (AJD1.Debit-AJD1.Credit) End) As Month2,
Sum(Case When OJDT.RefDate <= '2008-03-31' Then (AJD1.Debit-AJD1.Credit) End) As Month3,
Sum(Case When OJDT.RefDate <= '2008-04-30' Then (AJD1.Debit-AJD1.Credit) End) As Month4,
Sum(Case When OJDT.RefDate <= '2008-05-31' Then (AJD1.Debit-AJD1.Credit) End) As Month5,
Sum(Case When OJDT.RefDate <= '2008-06-30' Then (AJD1.Debit-AJD1.Credit) End) As Month6,
Sum(Case When OJDT.RefDate <= '2008-07-31' Then (AJD1.Debit-AJD1.Credit) End) As Month7,
Sum(Case When OJDT.RefDate <= '2008-08-31' Then (AJD1.Debit-AJD1.Credit) End) As Month8,
Sum(Case When OJDT.RefDate <= '2008-09-30' Then (AJD1.Debit-AJD1.Credit) End) As Month9,
Sum(Case When OJDT.RefDate <= '2008-10-31' Then (AJD1.Debit-AJD1.Credit) End) As Month10,
Sum(Case When OJDT.RefDate <= '2008-11-30' Then (AJD1.Debit-AJD1.Credit) End) As Month11,
Sum(Case When OJDT.RefDate <= '2008-12-31' Then (AJD1.Debit-AJD1.Credit) End) As Month12

FROM MSPLC.dbo.AACT AACT, MSPLC.dbo.AJD1 AJD1, MSPLC.dbo.OJDT OJDT

WHERE OJDT.TransId = AJD1.TransId AND AACT.AcctCode = AJD1.Account

Group By AACT.FormatCode, AACT.AccountName

_____________________________________________________________________

Thanks for any help in advance

elancaster
A very urgent SQL Yakette

1208 Posts

Posted - 2008-08-08 : 06:41:43
dup...
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=108388

Em
Go to Top of Page
   

- Advertisement -