>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)
>
> print @PATH + @Filename + ' exists'
>else
>
> 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.
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.