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 2005 Forums
 Transact-SQL (2005)
 Find id where they don't equal then insert

Author  Topic 

jgonzalez14
Yak Posting Veteran

73 Posts

Posted - 2008-11-13 : 14:51:18
I am trying to make a query that will select all T.Hotel where T.Hotel does not equal P.Inncode. The query below finds where the are equal to each other but when I change the = to <> it returns where T.Hotel <> P.Inncode but it returns 30,000 records (there is only like 100 records total) Now if I code get this 'does not equal' How can I insert this in to P.Hotel?

Thanks


SELECT      T.Hotel, P.Inncode
FROM ME_Hotels AS T INNER JOIN
MeetingExcellence_Hotels AS P ON T.Hotel = P.Inncode

jgonzalez14
Yak Posting Veteran

73 Posts

Posted - 2008-11-13 : 14:59:22
Ah I figured it out

SELECT Hotel AS NOTIN
FROM ME_Hotels AS T
WHERE (Hotel NOT IN
(SELECT Inncode
FROM MeetingExcellence_Hotels))


But now how can i make a dynamic insert statement in to MeetingExcellence_Hotels?
Go to Top of Page

jgonzalez14
Yak Posting Veteran

73 Posts

Posted - 2008-11-13 : 15:07:26
and I figured the insert issue to

INSERT INTO MeetingExcellence_Hotels
(Inncode, Hotel)
SELECT Hotel, Inncode
FROM ME_Hotels AS T
WHERE (Hotel NOT IN
(SELECT Inncode
FROM MeetingExcellence_Hotels))

thanks
Go to Top of Page
   

- Advertisement -