if @user_id is not null
begin
.........
end
Else
Begin
......
End
If is slightly different than in many other languages. When you write an If statement, it will consider whatever is on the nesxt line as the command it will execute if the if condition is met. To get more than one line to be recognized you must use begin, then the commands, then end. This still ahs you with the first block of the if, it does not end the if statement per se as an End if statment does. Therefore, the else comes after the first set of begin-end statements. As a good practice, I a;ways use the begin and end even if I am only using one line right now because that may change in the future and it makes it easier to maintain and to tell exactly what is in the if. Otherwise it is easy to have errors becasue you forgot to use the begin and end block and meant to put more than one line in the if.