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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Select Statement

Author  Topic 

Vack
Aged Yak Warrior

530 Posts

Posted - 2009-10-05 : 13:38:47
The code below gives me the following data:

GLAccount Per_fin bkjrcode Debit Credit
41401 1 2009 0 47.79
41401 3 2009 15.84 63.15
41401 6 2009 20.54 43.84


Is there a way to have it return:

GLAccount Per_fin bkjrcode Debit Credit
41401 1 2009 0 47.79
41401 2 2009 0 0
41401 3 2009 15.84 63.15
41401 4 2009 0 0
41401 5 2009 0 0
41401 6 2009 20.54 43.84


 SELECT grtbk.reknr AS GLAccount, '' as bal_vw,MONTH(gbkmut.datum) per_fin, YEAR(gbkmut.datum) bkjrcode ,  isnull(SUM(CASE WHEN TransSubType NOT IN ('R','S')  THEN CASE WHEN bdr_hfl >= 0 THEN (bdr_hfl) ELSE 0 END  ELSE CASE WHEN bdr_hfl < 0  THEN (bdr_hfl) ELSE 0 END END),0) AS Debit, 
isnull(SUM(CASE WHEN TransSubType NOT IN ('R','S') THEN CASE WHEN bdr_hfl >= 0 THEN 0 ELSE -(bdr_hfl) END ELSE CASE WHEN bdr_hfl < 0 THEN 0 ELSE -(bdr_hfl) END END),0) AS Credit FROM gbkmut WITH (NOLOCK) INNER JOIN grtbk ON gbkmut.reknr = grtbk.reknr
WHERE gbkmut.Datum BETWEEN {d '2009-01-01'} AND {d '2009-08-31'} AND grtbk.bal_vw = 'W' AND grtbk.subtotrek = 'N' AND gbkmut.transtype IN ('N', 'C')
GROUP BY grtbk.reknr, MONTH(gbkmut.datum), YEAR(gbkmut.datum)
ORDER BY grtbk.reknr, MONTH(gbkmut.datum), YEAR(gbkmut.datum)

X002548
Not Just a Number

15586 Posts

Posted - 2009-10-05 : 13:43:58
what is perf_fin??? a Month?

In any case looks like you will need a numbers table



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

gvphubli
Yak Posting Veteran

54 Posts

Posted - 2009-10-05 : 13:53:40

Did you try applying GROUP BY on "Per_fin" column too ?


TechnologyYogi
http://gvphubli.blogspot.com/
Go to Top of Page
   

- Advertisement -