SQL Server 中的字符串是用char,nchar,varchar,nvarchar等数据类型来实现的。
将int数据类型如何转换为字符串可以用如下任意一种方式:
declare @num int
set @num = 1
– 方式1:搜索
select CONVERT(varchar(10),@num)
– 或者方式2
select CAST(@num as varchar(10))
例1:
use MyDatabase
begin
declare @test_var1 int,@test_string1 varchar(60)
set @test_var1=98
set @test_string1=
case
when @test_var1>=90 and @test_var1<=100 then '优秀'
when @test_var1>=80 and @test_var1<=90 then '良好'
when @test_var1>=60 and @test_var1<=80 then '及格'
else '不及格'
end
print '学员的成绩为:'+convert(varchar(10),@test_var1)
print '学员的等级为:'+@test_string1
end
参考:百度知道