|
技术资料 > ASP技术 > 数据库相关 : SQL Server对select语句返回多条记录给变量赋值时的处 |
SQL Server对select语句返回多条记录给变量赋值时的处 March 25,2004 |
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字段值
|
|
Copyright © 2001-2008 Shenzhen Hiblue Software Team All rights reserved