We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

db2 query

dmala2
dmala2 asked
on
Medium Priority
597 Views
Last Modified: 2012-05-11
I'm trying to unload some counts using dsntiaul, i think we are on version 8 for db2 and wondering how i can force it to return me the 0 count
so in this query below, i have data for company '02' but not for the status E so I would like it to rertun 0, it's only showing the count for existing '01'
SELECT,CO_ID, SUBSTR(';', 1, 1),
       SUBSTR('LAPSED     ', 1,11),
       CHAR( COUNT(*))
       FROM JIT0.TPOL
       WHERE CO_ID IN ('01','02')
       AND POL_CSTAT_CD = 'E'
       AND POL_STAT_CHNG_DT BETWEEN '2011-04-01' AND '2011-04-27'
       GROUP BY CO_ID
       ;
Comment
Watch Question

you will have to use a left outer join to a table that has a list of the statuses
this can also be done like this

SELECT t2.CO_ID, SUBSTR(';', 1, 1),
       SUBSTR('LAPSED     ', 1,11),
       CHAR( COUNT(*))
       FROM (select '01' co_id from sysibm.sysdummy1 union all select '02' from sysibm.sysdummy1) t2
                 left outer join  JIT0.TPOL t1 on t1.co_id = t2.co_id
       WHERE
       POL_CSTAT_CD = 'E'
       AND POL_STAT_CHNG_DT BETWEEN '2011-04-01' AND '2011-04-27'
       GROUP BY t2.CO_ID
       ;
Data Engineer
CERTIFIED EXPERT
Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview

Author

Commented:
AWESOME!  The second one works great!  I just put a char back around it so the unload was nice and formatted.  Too cool, I really appreciate it!

Author

Commented:
Thank you!
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.