Wrox Programmer Forums
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 19th, 2005, 03:59 PM
Authorized User
 
Join Date: Jun 2004
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

 
Old September 20th, 2005, 02:14 PM
Authorized User
 
Join Date: Sep 2005
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
 
Old September 21st, 2005, 02:10 AM
Authorized User
 
Join Date: Oct 2004
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?
 
Old September 21st, 2005, 07:06 AM
Authorized User
 
Join Date: Sep 2005
Posts: 95
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes, it is, it's part of the join statement





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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.