I have a query, where I have to compare Due Dates and I can't seem to get my CASE expression to work properly.
At the moment I have commented out the original ELSE clause, which I thought could do the trick, but unfortunately, it just gives me an error "Argument 1 of function CASE not valid. Cause . . . . . : The data type, length, or value of argument 1 of function CASE specified is not valid."
Any ideas? I'm operating on an IBM DB2.
The desired result for the ELSE clause would be to add the Invoice date (AHINVD) and Invoice Due Date Code (CMDDCD) to get the Original Invoice Due Date.
Select
CMCMP as CompanyCode
,CMCUS# as CustomerCode
,CMNAME as CustomerName
,CMDDCD as InvoiceDuteDateCode
,AHINV# as InvoiceNumber
,AHISEQ as InvoiceSequence
,AHINVD as InvoiceDate
,AHDUED as InvoiceDueDate
,case
when date(to_date(RTRIM(AHINVD),'YYYYMMDD')) + cast(CMDDCD as INT) days = date(to_date(RTRIM(AHDUED),'YYYYMMDD')) then NULL
--else date(to_date(RTRIM(AHINVD),'YYYYMMDD')) + cast(CMDDCD as INT) days
else '12'
end as OriginalInvoiceDueDate
,AHAMT$ as OriginalAmount
,AHCURC as CurrencyCode
from WSDATARG.CUSMASFL cm
left join WSDATARG.ARIHDRFL ar
on CMCMP = AHCMP
and CMCUS# = AHCUS#
where CMCMP = '14'
and AHINVD > '20180918