在select语句中将数据类型varchar转换为numeric时出错

时间:2016-10-11 07:46:26

标签: sql

表格结构:

(code VARCHAR(5),
description VARCHAR(150),
tax_rate DECIMAL(5,2),)


SELECT t1.code AS code, t1.code AS value, t1.code AS description,
       t1.code + (' + tax_rate + '%)' AS content
 FROM pbostaxinfo t1

'tax_rate'提示将数据类型varchar转换为数字时出错。

我希望结果显示例如:AJP(6%)。

AJP是代码,6是tax_rate。

2 个答案:

答案 0 :(得分:2)

SELECT t1.code AS code, t1.code AS value, t1.code AS description, t1.code + ' (' + CAST(t1.tax_rate AS VARCHAR(5)) + '%)' AS content
FROM pbostaxinfo t1

这就是我所寻找的答案。

答案 1 :(得分:1)

  SELECT t1.code AS code,
  t1.code      AS value,
  t1.code      AS description,
  t1.code
  ||'('
  ||tax_rate
  ||'%)' AS content
  FROM pbostaxinfo t1