Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Select Where In Operator with Insert Into SQL 2005 SP2

$
0
0

I'm trying to do the following:

INSERT INTO [dbo].[table]

                      ([Column 1)
                      ,[Column 2]
                      ,[Column 3]
                      ,etc...)

SELECT * FROM dbo.matchingtable

WHERE ID IN ('ID1','ID2','ID3',etc...)

What seems to be happening is that it's ignoring the IN operator and just trying to insert all records causing duplicate key errors. The select statement alone works properly as I am just trying to insert based on a simple ID field criteria (list of various ID's). I've used this a lot with the UPDATE statement but I'm having an issue running it with the INSERT. It works fine if I use an 'OR' statement for each ID but that seems rather silly if I could just use the 'IN' operator.

This is happening on SQL 2005 SP2. Any advice is welcome. Thanks!


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>