Bracket for IF statement in stored procedure

I know this is such a stupid question, but I tried all the brackets I can think of to wrap the IF statement, but it seems like none of them work.

For instance:

IF(@item!=0){ //Do stub RETURN // without the brakets , this return does not belong to if } //Do some stubs // and if the condition of the IF is false, this statement can't be reached 

thanks

+4
source share
2 answers

try to start and end

 IF(@item!=0) begin /*Do stub*/ RETURN /* without the brakets , this return does not belong to if */ end 
+11
source

Instead of RETURN you can also use ELSE :

 if @item != 0 begin -- Do stub end else begin -- Do some stubs -- and if the condition of the IF is false, this statement can't be reached end 

A plus:

  • you don't need brackets around the IF clause
  • you need to use -- instead of // for comments (see my example)
+3
source

All Articles