代替的if..else的,你可以檢查行數(或其他標準)的@@值均選擇後,並返還或在腳本結束後藤標籤如果該值大於0.它仍然是很多有條件的檢查,但嵌套不會很難管理。
例如
declare @vals table (id int)
Declare @rc int
Insert into @vals (id) values (1)
Select * from @vals
set @rc = @@ROWCOUNT
if @rc <> 0
Begin
Print 'Exiting Early'
return
End
Select * from @vals
Select * from @vals
Select * from @vals
Select * from @vals
Select * from @vals
或者
declare @vals table (id int)
Declare @rc int
Insert into @vals (id) values (1)
Select * from @vals
set @rc = @@ROWCOUNT
if @rc <> 0
Begin
Print 'Exiting Early'
GOTO EarlyExit
End
Select * from @vals
Select * from @vals
Select * from @vals
Select * from @vals
Select * from @vals
EarlyExit:
Print 'We are done here'
當然OMG!謝謝你。這裏的星期天很慢。大聲笑 – super9 2009-08-09 12:16:48
np,很高興我能幫上忙。 – cmsjr 2009-08-09 12:18:39