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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 joining a data of 2 tablue

Author  Topic 

pelegk2
Aged Yak Warrior

723 Posts

Posted - 2006-01-03 : 03:19:08
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 data
1 6512 zxsdfsdf null
2 9845 sdbvdf null
3 12354 rdfv null


table2 :
id iduser name data
1 6512 zxsdfsdf 128
2 9845 sdbvdf 698
3 12354 rdfv 689

and i wantto join this 2 tables into 1
and recive all the rows from table 1 but with the data like in the "data" column
that will appear in the new table
is this possible?
thanks in advance

peleg

Israel -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> b
where a.id = b.id
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-01-03 : 03:39:08
OR
Use COALESCE to obtain first nonnull value from either table1 or table2
select	t1.id, t1.iduser, t1.name, COALESCE(t1.data, t2.data) as data
from table1 t1 inner join table2 t2
on t1.id = t2.id


-----------------
[KH]

a new beginning
Go to Top of Page
   

- Advertisement -