declare @userClass varchar(20) --用户功臣级别
declare @allCount int
set @allCount=@tcount+@rcount
CASE
when @allCount<10 then @userClass='新手上路' when @allCount between 10 and 20 then @userClass='侠客'
when @allCount between 21 and 30 then @userClass='骑士'
when @allCount between 31 and 40 then @userClass='精灵王'
when @allCount between 41 and 50 then @userClass='光明使者'
when @allCount > 50 then @userClass='法老'
END消息 156,级别 15,状态 1,第 35 行
关键字 'CASE' 附近有语法错误。
消息 102,级别 15,状态 1,第 43 行
'@allCount' 附近有语法错误。
declare @allCount int
set @allCount=@tcount+@rcount
CASE
when @allCount<10 then @userClass='新手上路'
when @allCount between 10 and 20 then @userClass='侠客'
when @allCount between 21 and 30 then @userClass='骑士'
when @allCount between 31 and 40 then @userClass='精灵王'
when @allCount between 41 and 50 then @userClass='光明使者'
when @allCount > 50 then @userClass='法老'
END
declare @allCount INTset @allCount=@tcount+@rcount;SELECT @userClass = CASE --注意这里
when @allCount<10 then '新手上路'
when @allCount between 10 and 20 then '侠客'
when @allCount between 21 and 30 then '骑士'
when @allCount between 31 and 40 then '精灵王'
when @allCount between 41 and 50 then '光明使者'
when @allCount > 50 then '法老'
END
declare @allCount int
declare @tcount int
declare @rcount int
select @tcount=22,@rcount=5
set @allCount=@tcount+@rcount
select @userClass=(CASE when @allCount<10 then '新手上路'
when @allCount between 10 and 20 then '侠客'
when @allCount between 21 and 30 then '骑士'
when @allCount between 31 and 40 then '精灵王'
when @allCount between 41 and 50 then '光明使者'
when @allCount > 50 then '法老'END)
print @userclass
use bbsDB
go
declare @tcount int,@rcount int--发帖数,回帖数
declare @uid int,@uname varchar(20)
set @uname='心酸果冻'
select @uid=uid from bbsusers where uname=@uname
set nocount on
if(@uid>0)--判断是否有该用户
begin
select @tcount=count(*) from bbstopic where TuID=@uid
if(@tcount>0)
begin
print @uname+'发帖数:'+convert(varchar(20),@tcount)+',帖子如下:'
select 发帖时间=convert(varchar(10),ttime,111),点击率=TclickCount,主题=Ttopic,内容=Tcontents
from bbstopic where TuID=@uid
end
else
print @uname+'发帖数:0'
select @rcount=count(*) from bbsReply where ruID=@uid
if(@rcount>0)
begin
print @uname+'回帖数:'+convert(varchar(20),@rcount)+',回帖如下:'
select 回帖时间=convert(varchar(10),rtime,111),点击率=RclickCount,回帖内容=Rcontents
from bbsReply where RuID=@uid
end
else
print @uname+'回帖数:0'
end
else
print '找不到该用户!'
declare @userClass varchar(20) --用户功臣级别
declare @allCount int
set @allCount=@tcount+@rcount
select @userClass=CASE
when @allCount<10 then '新手上路'
when @allCount between 10 and 20 then '侠客'
when @allCountt between 21 and 30 then '骑士'
when @allCount between 31 and 40 then '精灵王'
when @allCount between 41 and 50 then '光明使者'
when @allCount > 50 then '法老'
END
print @uname+'帖数总计:'+convert(varchar(20,@allCount))+'贴 功臣级别:'+@userClass
消息 137,级别 15,状态 2,第 38 行
必须声明标量变量 "@allCountt"。
消息 102,级别 15,状态 1,第 43 行
'@allCount' 附近有语法错误。
declare @allCount int
set @allCount=@tcount+@rcount
select @userClass=(CASE when @allCount<10 then '新手上路'
when @allCount between 10 and 20 then '侠客'
when @allCount between 21 and 30 then '骑士'
when @allCount between 31 and 40 then '精灵王'
when @allCount between 41 and 50 then '光明使者'
when @allCount > 50 then '法老' END)
print @uname+'帖数总计:'+rtrim(@allcount)+'贴 功臣级别:'+@userClass