Last post Dec 30, 2015 02:31 AM by oned_gk
Dec 29, 2015 08:18 PM|Arial12|LINK
I trying to do a join query on two tables which are not related but has one common column. I am doing a select statement and in which I would like to get all records where
if table a.column1 = table b.column1 and if table a. column1 is null then replace that with table b.column1 (not replacing actual table value in the table but just in the select statement)
and then return the result together.
select a.column1,b.column1, a.column2 ect.
from table a join table b on
a.column1 = b.column1 and case when a.column1 is null then
but this is not working. can someone help with this query?
Dec 29, 2015 08:34 PM|limno|LINK
select a.column1,b.column1, a.column2
from tablea a join tableb b
on ISNULL(a.column1,b.column1) = b.column1
Dec 29, 2015 10:12 PM|Arial12|LINK
Data is as such that I also have to check for a match on a last six characters as well.
right(a.column1,3) = right(b.column1,3) or isnull(a.column2,b.column1) = b.column1
Dec 29, 2015 10:20 PM|limno|LINK
For this type of T-SQL question, you need to mock up your question wtih table DDL (table structure and column data type) along with some sample data and your expected result. You help others to help you. Thanks.
Dec 30, 2015 02:31 AM|oned_gk|LINK
I guess you can't get the null records
First use join to get matched records, then use UNION ALL to combine with unmatched records
SELECT a.col1, b.col1 ....blablabla
SELECT col1, col1 as Col2 FROM a WHERE a.col1 NOT IN (SELECT col1 FROM b)
Try something like above