当前位置: 代码迷 >> Sql Server >> 怎么将int和char连接成一个字符串,然后输出
  详细解决方案

怎么将int和char连接成一个字符串,然后输出

热度:128   发布时间:2016-04-27 19:22:28.0
如何将int和char连接成一个字符串,然后输出?
declare @i int
declare @j char(1)
select @i=1,@j='2'
[email protected]@j连接为一个字符串,然后输出?

------解决方案--------------------
SQL code
declare @i int declare @j char(1) set @i=1 set @j='2' select 字符 = cast(@i as varchar) + @jselect 数字 = @i + cast(@j as int) /*字符                              ------------------------------- 12数字          ----------- 3*/
------解决方案--------------------
CAST 和 CONVERT
将某种数据类型的表达式显式转换为另一种数据类型。CAST 和 CONVERT 提供相似的功能。

语法
使用 CAST:

CAST ( expression AS data_type ) 

使用 CONVERT:

CONVERT (data_type[(length)], expression [, style])

  相关解决方案