Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Error with SET
Message
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Title:
Environment versions
SQL Server:
SQL Server 2005
Miscellaneous
Thread ID:
01324831
Message ID:
01324847
Views:
12
>>If I uncomment the two lines in the code below, I get this error:
>>
>>
>>Msg 156, Level 15, State 1, Line 134
>>Incorrect syntax near the keyword 'else'
>>
>>
>>The variable is declared and I am using the same SET with other variables.
>>
>>
>>if exists (select * from #a where s = @FileName)
>>	--SET @FileExists = 'Y'
>>	print @PATH + @Filename + ' exists'
>>else
>>	--SET @FileExists = 'N'
>>	print @PATH + @Filename + ' does not exist'
>>drop table #a
>>
>
>
>Jey,
>I see you have problems with BEGIN..END structure.
>That was my first big fight with TSQL, till I understood the logic. I was lucky I have experience with C++ :-)
>So in short;
>When you want some code block to be executed together put BEGIN ... END around it, no matter how many lines it have. I have one rule about it:
>If I have IF, WHILE I ALWAYS use BEGIN END no matter I use only one line after it. That way after a few days (weeks, months) i come back to this code and change something in IF I 'm always sure I'll do it in right place.

I had the same problem in 2003 when I first played a bit with T-SQL. I could not understand the syntax and you were not around to explain this to me :)
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform