Link to home
Start Free TrialLog in
Avatar of Euro5
Euro5Flag for United States of America

asked on

Query create decimal with division Teradata

I am getting an error "Corresponding select-list expressions are incompatible.
Can anyone tel by looking at this?

CASE 
  WHEN CAST(ZEROIFNULL(bill.shp_disc_amt + bill.bill_drop_off + bill.bill_to_natl_disc + bill.bill_to_mem_disc) * bill.exch_usd * -1 AS DECIMAL(12,2)) = 0 THEN 0
  ELSE CAST( CAST(ZEROIFNULL(bill.shp_disc_amt + bill.bill_drop_off + bill.bill_to_natl_disc + bill.bill_to_mem_disc) * bill.exch_usd * -1 AS DECIMAL(12,2)) /CAST(ZEROIFNULL(bill.shp_fgt_chrg_amt * bill.exch_usd) AS DECIMAL(12,2)) as DECIMAL(12,2))
END AS Effective_USD_Discount,

Open in new window

Avatar of lcohan
lcohan
Flag of Canada image

That is a general error that can show under many different circumstances and can you post the entire query assuming there is nothing confidential?
If you are 100000% certain that's where the error is then for sure one of the CASE values
 is not valid as they are not of the expected type and may need to get CAST-ed. or maybe is a divide by 0 error but I almost bet is in one of the columns used in additions.
Avatar of Euro5

ASKER

lcohan - the query is very large and worked until I added this line.
Do you have any suggestions?
As mentioned above - one of the CASE values is not valid as they are not of the expected type and you must check that against each and any of those underlying columns to make sure the all have data converging to you DECIMAL(12,2) desired cast data-type.
Avatar of Euro5

ASKER

lcohan - ah! Ok right...I will try that, great suggestion
So you will need to try validate the fact that each of those columns have numeric data and that data aggregated as per your query can fit the CAST-ed value
Avatar of Euro5

ASKER

Icohan, I broke it down to sections and am working through. I had success running the first instance, but this returns only 1.00 or 0.00, not the .63, .55, etc that I was expecting.
Can you by chance tell where I am going wrong?


CASE
WHEN CAST(ZEROIFNULL(bill.shp_disc_amt + bill.bill_drop_off + bill.bill_to_natl_disc + bill.bill_to_mem_disc) * bill.exch_usd * -1 AS DECIMAL(12,2)) = 0 THEN 0
ELSE CAST((CAST(ZEROIFNULL(bill.shp_disc_amt + bill.bill_drop_off + bill.bill_to_natl_disc + bill.bill_to_mem_disc) * bill.exch_usd * -1 AS DECIMAL(12,2)) /CAST(ZEROIFNULL(bill.shp_disc_amt + bill.bill_drop_off + bill.bill_to_natl_disc + bill.bill_to_mem_disc) * bill.exch_usd * -1 AS DECIMAL(12,2))) as decimal(12,2)) 
END AS Effective_Discount,

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of lcohan
lcohan
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Euro5

ASKER

I found it by using your guidance. Thank you!!