Možná byste mohli zvážit parametrizované SQL, pokud musíte provádět dynamické dotazy:
CREATE PROCEDURE sp_calculatesalary(@EmployeeId as int)
as
begin
declare @dynsql varchar(500)
declare @params nvarchar(500)
declare @salary money
declare @username varchar(50)
set @dynsql='Select @sal=Salary,@usernm=Username from employee where [email protected]'
set @params='@empID int, @sal money OUTPUT, @usernm varchar(50) OUTPUT'
exec sp_executesql @dynsql, @params, @[email protected], @[email protected] OUTPUT, @usernm = @username OUTPUT
SELECT @salary, @username
end