December 19, 2005 at 9:31 pm
Hello all,
My project requires me to build a single query for making some multiple field calculations. Also tried to build a Query with the help of a member here which is as below
SELECT
sum(case when LDGR_NO in (311000,312000) then LDGR_BAL_AM else 0 end) as [Sum1]
sum(case when LDGR_NO in (911000,912000) then LDGR_BAL_AM else 0 end) as [Sum2]
sum(case when LDGR_NO in (314000, 312000, 414000,454000) then LDGR_BAL_AM else 0 end) as [Sum3]
FROM DEVL8SGA.A_SGA_GRP_PSTN_SNP
WHERE ACCT_GRP_NO = 2100099
AND ACCT_NO = 791189
AND LDGR_NO IN (311000, 312000,911000, 912000,314000, 312000, 414000,454000 )
(The above query returns 3 values (Sum1, Sum2 Sum3) which are by adding up the ldgr_bal_am for 3 sets of ledger numbers found.
Tried to execute this in Db2, but it didnt work. Showed an error in 'case when LDGR_NO in (311000,312000) ....' Can anyone help me in this query and also suggest if there is any other way to Query this in Db2?.
Thanks.
December 19, 2005 at 11:10 pm
First, this isn't a DB2 forum and not all SQL's are created equal. That, notwithstanding, you say "it didn't work"... if you got an error message, is sure would be nice if you posted it.
My suspicion is that all you need to do is remove all the square brackets and everything should be fine.
You may have to change the table name... the convention used in the above code is username.tablename I don't know what DB2 uses for a convention.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply