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

存储过程中IF..GOTO,IF..ELSE的写法
求助SQL2000中存储过程中IF..GOTO,IF..ELSE的写法

if case @line = ''
  。。。
else
  。。。


类似这样的要怎么写啊

------解决方案--------------------
SQL code
--#1.
IF (1 = (CASE WHEN 1 = 1 THEN 1 ELSE 0 END)) --括号内可以是任意返回bool值的表达式, 返回值可以为true,false,null
BEGIN
    PRINT 'true'
END
ELSE
BEGIN
    PRINT 'false'
END

--#2.
IF (表达式)
BEGIN
    GOTO ShowMessage
END

ShowMessage:
BEGIN
    PRINT 'Hello, world!^^'
END

------解决方案--------------------
SQL code
if....else用法

if month(getdate())<7
begin
print('上半年')
select(getdate())
end
else
begin
print('下半年')
select(getdate())
end

--while,continue,break用法

declare @i int
set @i=1
while @i<20
begin
 set @i=@i+1
 if @i<=19
 continue
 print @i
end

declare @i int
set @i=1
while @i<20
begin
 if @i=19
 break
 print @i
 set @i=@i+1
end