Click here to Skip to main content
15,895,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi experts
i have two address tables like Address1 and CommonAddress

Address1 have Line1,Line2,Country,State,Zip
CommonAddress have Line1,Line2,State

i want sql query for if State is null in Address1 table it will be replace with State in CommonAddresswhen getting with same name of line1

please help me




Thanks in advance..
Posted

1 solution

COALESCE()[^] is what you want to use. It will return the first non-null value.

For example:
SQL
SELECT COALESCE(a.State, c.State) AS State, COALESCE(a.line1, c.line1) AS line1, etc...
FROM Address1 a
LEFT JOIN CommonAddress c ON ... whatever your join is
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900