Sqlserver
 sql >> Database >  >> RDS >> Sqlserver

Come restituire i valori da una stored procedure SQL dinamica a Entity Framework?

Forse potresti considerare SQL parametrizzato, se devi eseguire query dinamiche:

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