gpt4 book ai didi

sql - 无法使我的存储过程 IF 语句工作

转载 作者:行者123 更新时间:2023-12-04 22:26:49 25 4
gpt4 key购买 nike

存储过程 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com