DB2 Union All - blank date fields

I wrote an UNION ALL DB2 query statement and got the error msg below. How can I fix this?
**FYI, both statement run perfectly individually, but throw errors when I do UNION ALL.
Thanks.

"DB2 Database Error: ERROR [22007] [IBM][DB2/AIX64] SQL0180N  The syntax of the string representation of a datetime value is incorrect.  SQLSTATE=22007"
      

select
b.clrg_cor_num
,r.beta_rep_cd
,ar.beta_acct_num
,ar.lookup_1_txt
,t.cmpl_rstr_ind
,t.CMPL_RSTR_ADD_DT
,t.inac_36mo_ind
,t.INAC_36MO_ADD_DT
,''
,df.asset_amt as AUM


FROM DW.ACCT_REF AR

UNION ALL

select
b.clrg_cor_num
,r.beta_rep_cd
,ar.beta_acct_num
,ar.lookup_1_txt
,''
,''
,''
,''
,ar.DOC_RSTRCT_IND
,df.asset_amt as AUM


FROM DW.ACCT_REF AR
saved4useAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Terry WoodsIT GuruCommented:
I'd guess that t.CMPL_RSTR_ADD_DT and t.INAC_36MO_ADD_DT in the first query are datetimes. The second query is trying to select an empty string into a datetime column.

I'm no db2 expert, but hopefully that will help you. You might try using null or something like that instead of an empty string in the second query for those two columns.
0
momi_sabagCommented:
terry is correct
when you do union all the data types of the matching columns must be compatible
you can do
cast(null as date) instead of an empty string for the date columns and it should work
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
DB2

From novice to tech pro — start learning today.