Click here to Skip to main content
15,888,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Help ,

@exist bit output,
@SQL1 VarChar(max)

AS
DECLARE @query nvarchar(4000)
BEGIN
       
 @query =' if not exists( ' + @SQL1 + ' )
     Begin
        set '+ @exist=0 +'
      End
else
     Begin
        set'+ @exist=1 +'
        
     End '
EXEC(@query )
END



Error:Msg 134, Level 15, State 1, Procedure usp_chkMasterExist, Line 10
The variable name '@sql1' has already been declared. Variable names must be unique within a query batch or stored procedure.
Msg 102, Level 15, State 1, Procedure usp_chkMasterExist, Line 22
Incorrect syntax near 'END'.
Posted
Updated 27-Dec-10 20:20pm
v3
Comments
Dalek Dave 28-Dec-10 2:20am    
Edited for Readability.

There may be several errors in your SQL, but the error you mentioned is due to the fact that, the two variables @sql1 and @SQL1 are being considered as same by the SQL Server (Despite the fact that one is upper case and another is lower case).

Try renaming the @sql1 (Say, @sql2)
 
Share this answer
 
Comments
Dalek Dave 28-Dec-10 2:20am    
Good Answer.
Hm, strange procedure...
First, you have the argument and the variable with same names.
Second, you should use 'SET' to assign a variable:
set @sql = ...

Third, your @exist = ... must be inside the string

I would recommend you to read some tutorials about T-SQL
 
Share this answer
 
Comments
Dalek Dave 28-Dec-10 2:20am    
Good Advice.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900