tags:

views:

78

answers:

2
SELECT *
INTO Temp3

from

( SELECT B.Name
FROM [Temp2] as B 
WHERE B.Name
Not IN (
SELECT E.WorkerName
FROM WorkerDetail as E ) )

Why does this produce an error?

+1  A: 

Maybe Temp3 already exists? In MSSQL SELECT..INTO used to populate new table with data. If this table exist, you can use INSERT INTO .. SELECT FROM statement.

Alex_L
+2  A: 

If you want to use a derived table you need to alias it:

SELECT T1.*
INTO Temp3

from

( SELECT B.Name
FROM [Temp2] as B 
WHERE B.Name
Not IN (
SELECT E.WorkerName
FROM WorkerDetail as E ) )  AS T1

I'm not sure if you actually need to use a derived table, however.

This should also work:

SELECT B.Name
INTO Temp3
FROM [Temp2] as B 
WHERE B.Name
Not IN (
SELECT E.WorkerName
FROM WorkerDetail as E )
ivankolo