sql server - SQL Stored procedure delete duplicate records, keep one -
i'm using 3 tables tblproduct
, tblstock
, tblwinkel
.
there foreign keys productid
, winkelid
in tblstock
table.
the tblstock
table has field stock
well, integer.
i want have 1 record same combination of 2 foreign keys winkelid
, productid
. stock value of record contains sum of other records same foreign keys combination of winkelid
, productid
.
so, i'm trying delete other records same 2 foreign keys in it, keep 1.
my stored procedure keeps giving following error:
msg 155, level 15, state 2, procedure usprecordssamenvoegen, line 11
'int' not recognized cursor option.
little please ?
this stored procedure far:
set ansi_nulls on go set quoted_identifier on go create procedure usprecordssamenvoegen @winkelid int, @productid int begin declare stocktotaal int set nocount on select sum(stock) stocktotaal tblstock winkelid = @winkelid , productid = @productid; delete tblstock winkelid = @winkelid , productid = @productid; insert tblstock values(@winkelid, @productid, stocktotaal); end go
declare stocktotaal int
needs be
declare @stocktotaal int
without '@' declare variable, sql parser looking setup cursor. also, can't select variable. select should following:
select @stocktotaal = sum(stock) ...
Comments
Post a Comment