开发者

SQL server-declare local variable: "there is already an object named '' in the database"

开发者 https://www.devze.com 2023-01-18 18:28 出处:网络
I wrote the following stored procedure, in which I use a local variable \'syncParam\': declare @syncParam bit

I wrote the following stored procedure, in which I use a local variable 'syncParam':

declare @syncParam bit

select isSync into syncParam from MyTable where id=@id
if (@syncParam='True')..开发者_开发问答.
else ...  

return @syncParam

When I executed this stored procedure at the first time it worked, but after that I get the following error: "there is already an object named 'syncParam' in the database".

What did I miss?

Thanks in advance.


You want

select @syncParam  = isSync from MyTable where id=@id

SELECT INTO will insert records into a new table. Go look, you should have a syncParam table now.


you might consider using a temp table .. just rename the table #syncParam

0

精彩评论

暂无评论...
验证码 换一张
取 消