我有两张表,一张称为 Product,另一张称为 ProductVariant。ProductVariant 具有来自 Product 的 ID。我需要在两个表上做简单的操作。
这是我提出的查询:
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
但它给了我:Msg 154、Level 15、State 3、Line 4 变量赋值在游标声明中是不允许的。
谢谢