views:

18

answers:

2

Hello, Why is this query not working?

Delete  tblProduct
From    tblProduct
Inner Join @unwantedRows
On tblProduct.ProductId = @unwantedRows.ProductId;

Where @unwantedRows is

DECLARE @unwantedRows TABLE 
( 
    ProductId INT, 
    ProductName VARCHAR(50),
    Description VARCHAR(50),
    Category VARCHAR(50),
    Repetitions int

);

Thanks in advance :)

+3  A: 

You can't use the variable name in the join like that.

Try:

Delete  tblProduct
From    tblProduct
Inner Join @unwantedRows AS u
On tblProduct.ProductId = u.ProductId;
Ed Harper
+1  A: 

try this

Delete  tblProduct
From    tblProduct
WHERE tblProduct.ProductId IN (SELECT ProductId FROM @unwantedRows);
Flakron Bytyqi

related questions