Link to home
Start Free TrialLog in
Avatar of Neil Thompson
Neil ThompsonFlag for United Kingdom of Great Britain and Northern Ireland

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.

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 

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Anthony Perkins
Anthony Perkins
Flag of United States of America 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 Neil Thompson

ASKER

Thanks Anthony, its giving me this error when I paste it and try to run it. Apologies my SQL is ok at getting things with a select and join but nothing else :(

Error in SELECT clause: expression near 'CASE'.
Unable to parse query text.
Found it, just needed a , before case, thank you so much, saved me days of searching trying to do this :)