1
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?

11
  • Complete Sentences and Good Formating always Help :) Commented Jul 18, 2009 at 3:50
  • You will have to post all the table creation scripts too. Commented Jul 18, 2009 at 3:53
  • Hello, jame, are you there? Did you just ask the question and run away? Commented Jul 18, 2009 at 3:59
  • my given query does not work ......why?I want to insert value in temp3 Commented Jul 18, 2009 at 3:59
  • jame, please edit your question and show us the error you see. Commented Jul 18, 2009 at 4:04

2 Answers 2

2

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 ) 
Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.