動的クエリを実行する必要がある場合は、パラメータ化された SQL を検討できます:
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