日期:2014-05-17  浏览次数:20452 次

大家帮忙看下T-SQL

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 @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 @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

------解决方案--------------------
引用:
SQL code
?



12345678910111213141516171819202122232425262728293031323334353637383940414243444546

use bbsDB go declare @tcount int,@rcount int--发帖数,回帖数 declare @uid int,@uname varchar(20) set ……


多写个t吧
------解决方案--------------------
引用:
麻烦看下5#我贴了完整的代码。

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 @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