Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
i know i can use union to build 1 table from 2 tables.but can i join 2 same tables om diffrent DB's to 1 table,where say all the data that is null will recive the value from the correct column on the other db?for example : table1 :id iduser name data1 6512 zxsdfsdf null2 9845 sdbvdf null3 12354 rdfv nulltable2 :id iduser name data1 6512 zxsdfsdf 1282 9845 sdbvdf 6983 12354 rdfv 689and i wantto join this 2 tables into 1and recive all the rows from table 1 but with the data like in the "data" columnthat will appear in the new tableis this possible?thanks in advance pelegIsrael -the best place to live in aftr heaven 9but no one wan't to go there so fast -:)
shallu1_gupta
Constraint Violating Yak Guru
394 Posts
Posted - 2006-01-03 : 03:36:10
try this..select a.id,a.iduser,a.name,b.data from <table1> a, <dbname>.<owner>.<table2> bwhere a.id = b.id
khtan
In (Som, Ni, Yak)
17689 Posts
Posted - 2006-01-03 : 03:39:08
ORUse COALESCE to obtain first nonnull value from either table1 or table2
select t1.id, t1.iduser, t1.name, COALESCE(t1.data, t2.data) as datafrom table1 t1 inner join table2 t2 on t1.id = t2.id