开发者

Bracket for IF statement in Stored Procedure

开发者 https://www.devze.com 2023-03-27 11:29 出处:网络
开发者_运维百科I know this is such a silly question but I tried every bracket I can think of to wrap the IF statement but it seems that none of them work.

开发者_运维百科I know this is such a silly question but I tried every bracket I can think of to wrap the IF statement but it seems that none of them work.

For example:

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

Thank you


try begin and end instead

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


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

Plus:

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

精彩评论

暂无评论...
验证码 换一张
取 消