Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Stored procedure:error in declaring local variable

Author  Topic 

m.p
Starting Member

2 Posts

Posted - 2010-10-03 : 08:48:10
hello,

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 works, but after that I get the following error: "there is already an object named 'syncParam' in the database".

What did I miss? Should I delete this object at the beginning of the stored procedure?

Thanks in advance.

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2010-10-03 : 09:27:54
With that syntax you now have a permanent table named [syncParam] in your database.
You want:
select @synParam = isSync from myTable where id = @id

Be One with the Optimizer
TG
Go to Top of Page

m.p
Starting Member

2 Posts

Posted - 2010-10-03 : 09:53:54
Thanks you very much!
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-10-04 : 09:36:38
if its bit your if condition should be

if @syncParam=1....

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-10-05 : 06:14:51
quote:
Originally posted by m.p

hello,

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 works, but after that I get the following error: "there is already an object named 'syncParam' in the database".

What did I miss? Should I delete this object at the beginning of the stored procedure?

Thanks in advance.



Have you worked on ORACLE before?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -