Neil Thompson
asked on
SQL to select certain fields then set a column 'price' depending is there is a match, or a difference 'price' if null
Hi
I need to be able to build a list of address references (UPRN) and cross match with another table looking up the same UPRN .
If there IS a match on the 2nd table then I need to set a price column to be 10.00 otherwise if there is no match (null) I want to set a price of 20.00
This code lists all the UPRN data from t_blpu and then if there is a UPRN match in t_refuse_garden_2014 also lists that in the column next to it.
Really all I want is every c_uprn from t_blpu then a set of prices next to each one depending if there is a match or not.
For info the c_uprn in t_blpu is prefixed '0000' hence the addition.
I need to be able to build a list of address references (UPRN) and cross match with another table looking up the same UPRN .
If there IS a match on the 2nd table then I need to set a price column to be 10.00 otherwise if there is no match (null) I want to set a price of 20.00
This code lists all the UPRN data from t_blpu and then if there is a UPRN match in t_refuse_garden_2014 also lists that in the column next to it.
Really all I want is every c_uprn from t_blpu then a set of prices next to each one depending if there is a match or not.
For info the c_uprn in t_blpu is prefixed '0000' hence the addition.
SELECT t_blpu.c_uprn, t_refuse_garden_2014.green_uprn
FROM t_blpu LEFT OUTER JOIN
t_refuse_garden_2014 ON t_blpu.c_uprn = '0000' + t_refuse_garden_2014.green_uprn
ORDER BY t_refuse_garden_2014.green_uprn DESC
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Found it, just needed a , before case, thank you so much, saved me days of searching trying to do this :)
ASKER
Error in SELECT clause: expression near 'CASE'.
Unable to parse query text.