如何将int转换为十进制过程SQL

时间:2015-12-03 13:06:52

标签: c# sql-server stored-procedures

我有这个过程

[...]
BEGIN
  SELECT ODMI.VLR_LABOR AS Labor,
         O.ID_ODM AS IdODM,
    FROM ODM O
    JOIN ODM_AREA_IMPACTO ODMI ON ODMI.ID_ODM = O.ID_ODM
    JOIN AREA A ON A.ID_AREA = ODMI.ID_AREA
   WHERE O.ID_ODM = xx

END

Labor是c#代码中的小数。
如何在执行程序时将ODMI.VLR_LABOR转换为deicmal。

我尝试CONVERT(DECIMAL(16,4), height/10.0) AS HeightDecimal但没有成功。

2 个答案:

答案 0 :(得分:1)

您使用变量height,但它并不存在于您的代码中。试试这个:

BEGIN
  SELECT CONVERT(DECIMAL(16,4), CONVERT(DECIMAL(16,4), ODMI.VLR_LABOR)/10.0) AS Labor
         O.ID_ODM AS IdODM
    FROM ODM O
    JOIN ODM_AREA_IMPACTO ODMI ON ODMI.ID_ODM = O.ID_ODM
    JOIN AREA A ON A.ID_AREA = ODMI.ID_AREA
   WHERE O.ID_ODM = xx

END

答案 1 :(得分:1)

SELECT
    CAST(ODMI.VLR_LABOR * 1. / 10 AS DECIMAL(18,4)) AS Labor,
    O.ID_ODM AS IdODM
FROM ODM O
JOIN ODM_AREA_IMPACTO ODMI ON ODMI.ID_ODM = O.ID_ODM
JOIN AREA A ON A.ID_AREA = ODMI.ID_AREA
WHERE O.ID_ODM = xx