O Aprendiz
O Aprendiz

Reputation: 55

How to convert int to decimal procedure SQL

I have this proc

[...]
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 is a decimal in c# code.
How to convert ODMI.VLR_LABOR to deicmal at the time of execution of the procedure.

I try CONVERT(DECIMAL(16,4), height/10.0) AS HeightDecimal but not success.

Upvotes: 1

Views: 155

Answers (2)

Maxim Goncharuk
Maxim Goncharuk

Reputation: 1333

You use variable height but it doesn't exist in your code. Try this:

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

Upvotes: 1

Devart
Devart

Reputation: 122002

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

Upvotes: 1

Related Questions