在 SQL 中,如何将字符串与整数数据类型列连接起来
In SQL, how to concatenate string with integer data type column
我正在尝试添加带有金额列的字符串 "Rs"。
金额的数据类型是整型。
但是 Sql 不允许我将字符串与 int 数据类型列连接起来。Image 1
Image 2
在与任何字符串连接之前,您需要明确地将 int
转换为 varchar
select 'RS'+cast(total_amount as varchar(100)),*
from yourtable
如果您是 sql 服务器 2012+ 然后使用 CONCAT
进行隐式转换
select Concat('RS',total_amount),*
from yourtable
我正在尝试添加带有金额列的字符串 "Rs"。 金额的数据类型是整型。 但是 Sql 不允许我将字符串与 int 数据类型列连接起来。Image 1
Image 2
在与任何字符串连接之前,您需要明确地将 int
转换为 varchar
select 'RS'+cast(total_amount as varchar(100)),*
from yourtable
如果您是 sql 服务器 2012+ 然后使用 CONCAT
进行隐式转换
select Concat('RS',total_amount),*
from yourtable