SQL语句嵌套if

时间:2015-11-06 06:45:27   收藏:0   阅读:632

在存储过程中我要实现一个IF的嵌套语句查询,类似与
if()
{
    if()
     {
        ......
     }
     else
     {
        ......
     }
}
else
{
    ......
}
请问这样的SQL语句要怎么写啊?

 

 

 

if(@a == ‘xxxx‘) 
BEGIN
    if(@B == ‘XXXXXXXXXXX‘) 
     BEGIN
          .........
    END
    else 
    BEGIN
         .........
    END 
END 
else
BEGIN 
    ...... 
END

 

 

if()
 begin
  if()
   begin
    `````
   end
   else
   begin
    ```
    end  
 end
else
 begin
 `````
 end
 
 

declare @a int,@b varchar(100)

set @a=(select count(titles_id) from titles);

set @b=convert(varchar(100),@a);

if @a<14

     select @a+1 as a

else

     begin

          select @b+‘2‘ as b

          select 900

     end

原文:http://www.cnblogs.com/caicaizi/p/4941365.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!