我使用3個表tblproduct
,tblstock
和tblwinkel
。SQL存儲過程刪除重複記錄,保留一個
tblstock
表中有外鍵productid
和winkelid
。
tblstock
表中還有一個字段stock
,它是一個整數。
我只想要有兩個外鍵winkelid
和productid
的相同組合的1條記錄。此記錄的股票價值包含具有相同外鍵組合winkelid
和productid
的所有其他記錄的總和。
所以,我想刪除所有其他記錄與它相同的2個外鍵,所以我只是保持1
我的存儲過程中一直給以下錯誤:
Msg 155, Level 15, State 2, Procedure uspRecordsSamenvoegen, Line 11
'int' is not a recognized CURSOR option.
請幫忙嗎?
這是迄今爲止我的存儲過程:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE uspRecordsSamenvoegen
@winkelid int, @productid int
AS
BEGIN
declare stocktotaal int
SET NOCOUNT ON
select sum(Stock) into stocktotaal from TblStock where WinkelId = @winkelid and ProductId = @productid;
delete from TblStock where WinkelId = @winkelid and ProductId = @productid;
insert into TblStock values(@winkelid, @productid, stocktotaal);
END
GO
是winkelid和productid傳遞給uspRecordsSamenvoegen? – Beth