I have two tables, one is called Product and another one is called ProductVariant. ProductVariant has ID from Product. I need to do simple operation on both tables.
Here is the query that I come up with:
declare @id int
declare cur CURSOR LOCAL for
select @id = ProductID from Product WHERE (Published = '0')
open cur
fetch next from cur into @id
while @@FETCH_STATUS = 0 BEGIN
UPDATE Productvariant SET Cost = SalePrice WHERE VariantID = @id;
UPDATE ProductVariant SET SalePrice = 0.00 WHERE VariantID = @id;
fetch next from cur into @id
END
close cur
deallocate cur
But it gives me:
Msg 154, Level 15, State 3, Line 4
variable assignment is not allowed in a cursor declaration.
Thanks
I would do something like this instead.
SQL Fiddle
MS SQL Server 2008 Schema Setup:
Query 1:
Results: