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
 Transact-SQL (2000)
 Join between 2 tables from 2 different databases

Author  Topic 

ragh
Starting Member

34 Posts

Posted - 2003-01-06 : 06:33:27
hi !
How Can i join 2 tables of similar structures between 2 different databases, and it should return 1 if found eqality or else return 0 if not found.

example:
Table 1
name rollno mark
---------- ----------- -----------
ragh 121 12
def 1 1

Table 2
name rollno mark
---------- ----------- -----------
RAGH 121 12
SDF 1 1
It should return 1 for RAGH or Return 0 For DEF and SDF !
please let me know...!if the procedure is in genereic form then it will be good !

regards,

Ragh

nr
SQLTeam MVY

12543 Posts

Posted - 2003-01-06 : 06:53:57
select coalesce(a.name, b.name) ,
case when a.rollno = b.rollno and a.mark = b.mark then 1 else 0 end
from db1..tbl a
full outer join db2..tbl b
on a.name = b.name

You can create a generic SP by using the system tables to generate a dynamic sql statement using the PK.


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -