INSERT INTO using WHERE

insert, sql-server-2008

Solution

The issue is your `WHERE` clause - you can't compare sets of fields like this. You can only compare a single field at a time.

Try instead:

WHERE View_1.JobNo NOT IN(SELECT JobNo FROM Table_1) 
AND View_1.CellNo NOT IN (SELECT CellNo FROM Table_1)

Alternatively you can use a single `EXISTS` statement:

INSERT INTO Table_1(ID, JobNo, CellNo)
SELECT View_1.ID, View_1.JobNo, View_1.CellNo
FROM View_1 v
WHERE NOT EXISTS (SELECT 1 FROM Table_1 t
                  WHERE t.JobNo = v.JobNo
                  AND t.CellNo = v.CellNo)

Problem

I'm trying to insert the `JobNo` and `CellNo` columns that are not in `Table_1` from `View_1`. I wrote this query & I get an error. Please help me out in correcting this. I'm using SQL Server 2008 ``` INSERT INTO Table_1(ID, JobNo, CellNo) SELECT View_1.ID, View_1.JobNo, View_1.CellNo FROM View_1 WHERE View_1.JobNo AND View_1.CellNo NOT IN (SELECT JobNo, CellNo FROM Table_1) ```

Original source