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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Variable names must be unique within a query batch

Author  Topic 

lovehui
Yak Posting Veteran

60 Posts

Posted - 2009-08-13 : 10:38:26
Hello,

I got this error
The variable name '@EMPID' has already been declared. Variable names must be unique within a query batch or stored procedure.


CREATE PROCEDURE [dbo].[Detail]
@PeriodType varchar(255),
@EmpID varchar(255),
@Register VARCHAR(50),
@SpecificPeriod varchar(255)

AS
begin
declare @@rc int /* return code for called stored procedures */
declare @sqlRC int
declare @errMsg varchar(255)

declare ....



set nocount on
set arithabort off
set arithignore on



create table #TmpJnlData(
.....
)


declare JnlCursor CURSOR

FOR SELECT DISTINCT (EMP_ID) from #TmpJnlData
declare @EMPID varchar(50)

OPEN JnlCursor
FETCH NEXT FROM JnlCursor INTO @EMPID
WHILE @@Fetch_Status = 0
BEGIN....
If I comment out @EMPID in my SQL SERVER Management Studio 2005
, then the error disappeared.
The question is that in another machine,if I comment it out, the error will show up. If I uncomment it out, the error will occur.

I don't know why. Both machine have the same version SQL SERVER.

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-08-13 : 10:39:51
You already have @EmpID declared in your procedure header, as an input parameter.



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

lovehui
Yak Posting Veteran

60 Posts

Posted - 2009-08-13 : 10:51:45
The question is that in another machine,if I comment it out, the error will show up. If I uncomment it out, the error will occur.

I don't know why. Both machine have the same version SQL SERVER.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-08-13 : 10:54:41
Do you have more @EmpID declares?



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

lovehui
Yak Posting Veteran

60 Posts

Posted - 2009-08-13 : 11:00:04
No.
Go to Top of Page

YellowBug
Aged Yak Warrior

616 Posts

Posted - 2009-08-13 : 11:05:19
Do the servers have the same collation?
Or is one server/database case-sensitive? And the not not?
Go to Top of Page

lovehui
Yak Posting Veteran

60 Posts

Posted - 2009-08-13 : 11:41:32
I don't know and how can I investgate them?
Go to Top of Page
   

- Advertisement -