SQL Server 2008 中,将int数据类型如何转换为string输出?

来源:互联网 发布:乔致庸 知乎 编辑:程序博客网 时间:2024/05/22 09:04

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 MyDatabasebegindeclare @test_var1 int,@test_string1 varchar(60)set @test_var1=98set @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 '不及格'endprint '学员的成绩为:'+convert(varchar(10),@test_var1)print '学员的等级为:'+@test_string1end

参考:百度知道

0 0
原创粉丝点击