declare @user nvarchar(20)
select @user='user1'
use countme
/*判斷用戶是否存在*/
declare @userweek int
select @userweek=[week] from base where userid=@user
select @@rowcount
if @@rowcount=0
return
select @userweek
最後的@userweek打印出來的結果就是記錄用戶名為user1的week字段的值
而當我們用下面的語句選擇所有記錄時(沒有where限制)
declare @user nvarchar(20)
select @user='user1'
use countme
/*判斷用戶是否存在*/
declare @userweek int
select @userweek=[week] from base
select @@rowcount
if @@rowcount=0
return
select @userweek
最後@userweek打印出來的值是返回的所有記錄中排名最後一條記錄的week字段值