ALTER PROCEDURE cal_updCatFromValues
(
@shid bigint
)
AS
DECLARE @myvar int
SELECT @myvar=count(*) FROM pricecategory where shid=@shid
exec('UPDATE calendar SET price='+ @myvar +' WHERE shid=@shid AND price >'+ @myvar)
ALTER PROCEDURE cal_updCatFromValues
(
@shid bigint
)
AS
DECLARE @myvar int
SELECT @myvar=count(*) FROM pricecategory where shid=@shid
exec('UPDATE calendar SET price='+ @myvar +' WHERE shid='+@shid+' AND price >'+ @myvar)
UPDATE calendar SET price=
(select count(*)
from pricecategory
where shid = @shid)
WHERE shid=@shid
AND price > (select count(*)
from pricecategory
where shid = @shid)
i vilket fall som helst så skall du inte använda dynamisk SQL.