存储过程IF语句不起作用

    @manuel varchar(50),
    @tour int,
    @tourname varchar(50) OUTPUT ,
    @pricetax int output

    AS BEGIN  -- SET NOCOUNT ON added to prevent extra result sets from  -- interfering with SELECT statements.  SET NOCOUNT ON;      -- Insert statements for procedure here

    if @manuel = 'no' then

    SET @tourname = (select [title] from files.dbo.tours where tour = @tour)

    SET @pricetax = (select top 1 [adult] from files.dbo.trprices where tour = @tour)


    select distinct CONVERT(varchar(12),CAST(CAST(ddate7 AS CHAR) AS DATETIME),101) as ddate7 from files.dbo.TDEPART where tour = @tour and depart > convert(int,getdate())  and status = 'OK'


    else if @manuel='yes' then

     SET @tourname = (select [title] from files.dbo.tours where tour = @tour)

    SET @pricetax = (select top 1 [adult] from files.dbo.trprices where tour = @tour)


    select distinct CONVERT(varchar(12),CAST(CAST(ddate7 AS CHAR) AS DATETIME),101) as ddate7 from files.dbo.TDEPART where tour = 2525 and depart > convert(int,getdate())  and status = 'OK'




    END

最佳答案

您需要在每个if和else之间放置一个BEGIN和END,如下所示。

IF (@string = 'hello')
    BEGIN
       --some code
    END
ELSE
    BEGIN
        --some code
    END

希望这可以帮助。

关于sql - 无法使我的存储过程IF语句正常工作,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4935461/

10-12 17:46