Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Dec 03, 2012 02:53 PM by nikunjnandaniya
Member
1 Points
4 Posts
Dec 01, 2012 07:36 AM|LINK
Please Help !!
I have 2 databases in single server, I m using query for sql server 2005.
Let say
db1 with table1 and column name 'CustomerID' entries like '12/2571', '12/2684', '12/6589', '12/9874' .......
db2 with table2 and column name 'C_ID' entries like '12/2571', '12/1235', '12/6589', '12/7854' .......
But both entries in column 'CustomerID' and column 'C_ID' are in of same datatype and pattern.
Now my requirement is to display only those customerID(s) which r in db1 with table1 but not in C_ID(s) db2 with table2 ??
for eg. Like CustomerID' entries like '12/2684', '12/9874' are not in C_ID and need to be displayed in single query.
Thanks in advance!!
551 Points
145 Posts
Dec 01, 2012 11:27 AM|LINK
You Need to use join query
and table you can refer with dbo.dbname.tablename this way you can refer the table from the other database.
Participant
882 Points
223 Posts
Dec 01, 2012 12:29 PM|LINK
Hii,
SeLect T1.* FROM Table_1 AS T1 LEFT JOIN [db2].dbo.Table_1 AS T2 ON T1.id = T2.id WHERE T2.id IS NULL
I considerd that you run this query on db1.
you can also use not in.
9 Points
20 Posts
Dec 03, 2012 06:55 AM|LINK
Thanks
Its working with
SeLect T1.id FROM Table_1 AS T1 LEFT JOIN [db2].dbo.Table_1 AS T2 ON T1.id = T2.id WHERE T2.id IS NULL
Thanks!!
Dec 03, 2012 02:53 PM|LINK
Please mark as answer if it is works for you.
GIRRAJ
Member
1 Points
4 Posts
Query for sql server 2005
Dec 01, 2012 07:36 AM|LINK
Please Help !!
I have 2 databases in single server, I m using query for sql server 2005.
Let say
db1 with table1 and column name 'CustomerID' entries like '12/2571', '12/2684', '12/6589', '12/9874' .......
db2 with table2 and column name 'C_ID' entries like '12/2571', '12/1235', '12/6589', '12/7854' .......
But both entries in column 'CustomerID' and column 'C_ID' are in of same datatype and pattern.
Now my requirement is to display only those customerID(s) which r in db1 with table1 but not in C_ID(s) db2 with table2 ??
for eg. Like CustomerID' entries like '12/2684', '12/9874' are not in C_ID and need to be displayed in single query.
Thanks in advance!!
Shailendra S...
Member
551 Points
145 Posts
Re: Query for sql server 2005
Dec 01, 2012 11:27 AM|LINK
You Need to use join query
and table you can refer with dbo.dbname.tablename this way you can refer the table from the other database.
www.techaray.com
nikunjnandan...
Participant
882 Points
223 Posts
Re: Query for sql server 2005
Dec 01, 2012 12:29 PM|LINK
Hii,
I considerd that you run this query on db1.
you can also use not in.
Nikunj Nandaniya
My Blog
advensql
Member
9 Points
20 Posts
Re: Query for sql server 2005
Dec 03, 2012 06:55 AM|LINK
Thanks
Its working with
nikunjnandan...
Participant
882 Points
223 Posts
Re: Query for sql server 2005
Dec 03, 2012 02:53 PM|LINK
Hii,
Please mark as answer if it is works for you.
Nikunj Nandaniya
My Blog