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)
 NOT IN

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_employee
WHERE [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 t
LEFT JOIN ST.dbo.employee e
ON e.SharedID=t.ID
AND e.DummyId IS NULL
WHERE e.SharedID IS NULL
Go to Top of Page

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.
Go to Top of Page

Looper
Yak Posting Veteran

68 Posts

Posted - 2008-04-28 : 07:02:00
cheers guys that worked. yeah there was a null in there.

Go to Top of Page
   

- Advertisement -