Reg Help with DB2 query

  • 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.

  • 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


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply