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.
Author |
Topic |
Looper
Yak Posting Veteran
68 Posts |
Posted - 2008-04-28 : 04:44:37
|
I am using the query below to insert an ID into another database if it does not exist, however on my local pc this works fine but in my other test pc it does not work it comes back with no rows to insert when I clearly can see that it should. This is also working ok in our production environment?INSERT INTO ST.dbo.employee(DummyID, SharedID)SELECT NULL, [ID] from SH.dbo.t_employeeWHERE [ID] NOT IN (SELECT DISTINCT SharedID FROM ST.dbo.employee WHERE DummyId IS NULL) |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-04-28 : 05:42:33
|
Try using join instead and see if it works:-INSERT INTO ST.dbo.employee(DummyID, SharedID)SELECT NULL, [ID] from SH.dbo.t_employee tLEFT JOIN ST.dbo.employee eON e.SharedID=t.IDAND e.DummyId IS NULLWHERE e.SharedID IS NULL |
 |
|
RyanRandall
Master Smack Fu Yak Hacker
1074 Posts |
Posted - 2008-04-28 : 06:10:31
|
quote: in my other test pc it does not work it comes back with no rows
This is probably because there is a null SharedId in there...Ryan Randall Solutions are easy. Understanding the problem, now, that's the hard part. |
 |
|
Looper
Yak Posting Veteran
68 Posts |
Posted - 2008-04-28 : 07:02:00
|
cheers guys that worked. yeah there was a null in there. |
 |
|
|
|
|