I have this stored procedure:
Create Procedure spVerhoogPrijzen1
@artikelcategorie varchar(128),
@ingangsdatum date
as
begin transaction
update p
set prijs = prijs * 1.1
from artikelprijs p
join artikel a on a.artikelnr = p.artikelnr
join artikelcategorie c on c.catcode = a.catcode
where c.catomschrijving like @artikelcategorie
and p.begindatum >= @ingangsdatum
if @@ERROR <> 0
begin
rollback
Raiserror('Je hebt iets fouts ingevuld', 16, 1)
end
commit
But when I run it, it takes forever to create the procedure. I stopped it after 15 minutes.
I'm using SQL Server 2014 Management Studio.
Artikel contains:
401 Kaviaar lux
402 Ganzenlever lux
403 Vruchtenyoghurt Aardbei zuv
404 Volle Yoghurt zuv
405 Magere Kwark zuv
Artikelcategorie contains:
bio biologische artikelen
lux luxe artikelen van de traitteur
zuv zuivelartikelen
Artikelprijs contains:
401 21.50 2012-01-01 2099-12-31
402 38.95 2012-01-01 2012-12-31
402 39.95 2013-01-01 2013-10-31
402 37.00 2013-11-01 2099-12-31
403 16.25 2012-01-01 2013-07-31
2条答案
按热度按时间nbysray51#
Can you please try the following procedure
According to your join condition, one row is affected which catcode is 403 and value is 16.25. After update this value has changed to 17.88. Please check and Thanks.
yhxst69z2#
I don't think you need a transaction for a single statement.
Give this a try: