我使用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