Search code examples
sqlexception

Must declare the scalar variable "@id"


I know this question has been asked like a thousandth time. But the solutions given do not work for me. I have a very simple stored procedure like below:

alter procedure sp_updateVacancyWithRecruitment (@id int, @idList varchar(100) ) as EXEC('update Vacancy_team1 set recruitment_request_id=@id where id IN ('+@idList +')')

And even the following doesn't work :

exec sp_updateVacancyWithRecruitment @id=5,@idList='6,8'

What am I doing wrong?


Solution

  • OK . Got it . Syntax error. My bad. The correct procedure is : alter procedure sp_updateVacancyWithRecruitment (@id int, @idList varchar(100) ) as EXEC('update Vacancy_team1 set recruitment_request_id='+@id+' where id IN ('+@idList+')')