将数值转换为Varchar
问题描述:
我试图使用在我的数字列中附加一些alphabt来获取记录。 但我得到错误,我尝试使用投射和转换功能。将数值转换为Varchar
为〔实施例
select convert(varchar(10),StandardCost +'S')
from DimProduct where ProductKey = 212
这里StandardCost是一个数字字段,但是当我获取该记录我m到处错误 请看看。
答
我觉得应该是
select convert(varchar(10),StandardCost) +'S' from DimProduct where ProductKey = 212
或
select cast(StandardCost as varchar(10)) + 'S' from DimProduct where ProductKey = 212
+0
感谢Ocaso,MayP – 2011-03-16 09:57:16
答
首先转换成数值然后添加'S'
:
select convert(varchar(10),StandardCost) +'S'
from DimProduct where ProductKey = 212
如果您发布的代码,XML或数据样本, **请**在文本编辑器中突出显示这些行,然后在编辑器工具栏上单击“代码示例”按钮(“{}”)以很好地格式和语法突出显示它! – 2011-03-16 09:44:11