日期:2014-05-18  浏览次数:20637 次

SQL里if...eles 中怎样嵌套if语句?
我使用下面的语句,被告错!!

if(UPPER(@kind)   =   'HB ')

  BEGIN
SET   @ab   =   ((select   pno   from   sendHb   where   hbNo   =   @xNo)
        if(@ab   !=   ' ')
        BEGIN
INSERT   INTO   [MG].[dbo].[tb_queue]
SELECT   pno,spno,linkid,@phone_4   as   phone,msg,fee,userid,pwd,sid   FROM   sendHB   WHERE   hbNo   =   @xNo
        END
        else
        BEGIN
INSERT   INTO   [MG].[dbo].[tb_queue]
SELECT   pno,spno,linkid,@phone_4   as   phone,   '今天没有你所查询的信息! '   as   msg,fee,userid,pwd,sid   FROM   sendHB   WHERE   hbNo   =   @xNo
  --       END
END

------解决方案--------------------
if(UPPER(@kind) = 'HB ')
BEGIN
SET @ab = (select pno from sendHb where hbNo = @xNo)
if (@ab <> ' ')
BEGIN
INSERT INTO [MG].[dbo].[tb_queue]
SELECT pno,spno,linkid,@phone_4 as phone,msg,fee,userid,pwd,sid FROM sendHB WHERE hbNo = @xNo
end
END
else
BEGIN
INSERT INTO [MG].[dbo].[tb_queue]
SELECT pno,spno,linkid,@phone_4 as phone, '今天没有你所查询的信息! ' as msg,fee,userid,pwd,sid
FROM sendHB
WHERE hbNo = @xNo

END

------解决方案--------------------
语句的嵌套本身没有错误,检查下是不是其它的错误呢!