Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old September 19th, 2005, 03:59 PM
Authorized User
 
Join Date: Jun 2004
Location: York, East Yorkshire, United Kingdom.
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default Where Not In Insert

OK I think I'm having a moment of madness, I cannot figure out why this Insert Into Where Not In is not working, there are records in the tbl_distributor_isa table that are not in the tbl_catergory table but its not seeing them? What am I doing wrong?

INSERT INTO tbl_catergory
(tbl_catergory.scat1, tbl_catergory.scat1_desc, tbl_catergory.scat2, tbl_catergory.scat2_desc, tbl_catergory.distributor)
SELECT [Item Class], [Item Class Desc], [Product Type], [Product Type Desc], distributor
FROM tbl_distributor_isa
WHERE [Item Class] NOT IN
(SELECT scat1
  FROM tbl_catergory) AND[ Product Type]NOT IN
(SELECT scat2
 FROM tbl_catergory)

Any help gratefully received.

Stuart

Reply With Quote
  #2 (permalink)  
Old September 20th, 2005, 02:14 PM
Authorized User
 
Join Date: Sep 2005
Location: , , .
Posts: 95
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Try something like this (untested)

INSERT INTO tbl_catergory
(tbl_catergory.scat1, tbl_catergory.scat1_desc, tbl_catergory.scat2, tbl_catergory.scat2_desc, tbl_catergory.distributor)
SELECT [Item Class], [Item Class Desc], [Product Type], [Product Type Desc], distributor
FROM tbl_distributor_isa i left join tbl_catergory c on i.[Item Class] =c.scat1
and i.[Product Type] =c.scat2
where c.scat2 is null
Reply With Quote
  #3 (permalink)  
Old September 21st, 2005, 02:10 AM
Authorized User
 
Join Date: Oct 2004
Location: Bristol, Nth. Somerset, United Kingdom.
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
Default

SQLMenace,

Is it correct that the 'AND' is before the 'WHERE' in the code you have given?
Reply With Quote
  #4 (permalink)  
Old September 21st, 2005, 07:06 AM
Authorized User
 
Join Date: Sep 2005
Location: , , .
Posts: 95
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes, it is, it's part of the join statement
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to insert " ". Somesh C# 1 March 6th, 2007 08:45 AM
insert into U.N.C.L.E. SQL Language 3 June 6th, 2006 06:35 PM
trigger to insert current date on insert kev_79 SQL Server 2000 3 January 23rd, 2006 05:58 PM
Insert into jemacc SQL Server 2000 2 March 31st, 2004 08:31 AM
"INSERT INTO" kaz SQL Language 7 December 15th, 2003 07:40 PM



All times are GMT -4. The time now is 06:17 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.