【问题标题】:Convert Numeric value to Varchar将数值转换为 Varchar
【发布时间】:2011-03-16 09:39:22
【问题描述】:

我正在尝试获取记录并将一些字母附加到我的数字列中,但出现错误。我尝试了 cast 和 convert 功能。

例如:

select convert(varchar(10),StandardCost +'S')
from DimProduct where ProductKey = 212

这里StandardCost 是一个数字字段,但是当我获取记录时出现错误。

【问题讨论】:

  • 如果您发布代码、XML 或数据示例,在文本编辑器中突出显示这些行,然后单击编辑器上的“代码示例”按钮 ({ })工具栏以很好地格式化和语法突出显示它!

标签: sql sql-server-2005


【解决方案1】:

我觉得应该是

select convert(varchar(10),StandardCost) +'S' from DimProduct where ProductKey = 212

select cast(StandardCost as varchar(10)) + 'S' from DimProduct where ProductKey = 212

【讨论】:

    【解决方案2】:

    先转换数值再添加'S':

     select convert(varchar(10),StandardCost) +'S'
     from DimProduct where ProductKey = 212
    

    【讨论】:

      猜你喜欢
      • 2013-09-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-31
      • 1970-01-01
      • 2011-05-01
      相关资源
      最近更新 更多