SQL 将数值转换为 Varchar
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5323361/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Convert Numeric value to Varchar
提问by Praveen k. Agrawal
i m trying to fetch the record using append some alphabt in my numeric column. but i m getting error, i tried with cast and convert function.
我试图使用在我的数字列中附加一些 alphabt 来获取记录。但我遇到错误,我尝试使用强制转换和转换功能。
for exmaple
例如
select convert(varchar(10),StandardCost +'S')
from DimProduct where ProductKey = 212
here StandardCost is a numeric field, but when i fetch the record i m getting error please have a look.
这里的 StandardCost 是一个数字字段,但是当我获取记录时出现错误,请查看。
回答by MayureshP
i think it should be
我认为应该是
select convert(varchar(10),StandardCost) +'S' from DimProduct where ProductKey = 212
or
或者
select cast(StandardCost as varchar(10)) + 'S' from DimProduct where ProductKey = 212
回答by Ocaso Protal
First convert the numeric value then add the 'S'
:
首先转换数值然后添加'S'
:
select convert(varchar(10),StandardCost) +'S'
from DimProduct where ProductKey = 212