MyH*_*rts 2 sql t-sql sql-server sql-server-2005
存储过程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
Run Code Online (Sandbox Code Playgroud)
您需要在每个if和else之间放置一个BEGIN和END.
IF (@string = 'hello')
BEGIN
--some code
END
ELSE
BEGIN
--some code
END
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助.
| 归档时间: |
|
| 查看次数: |
7312 次 |
| 最近记录: |