Suraz Suraz - 1 month ago 5
SQL Question

Failed to return after decimal value while concenating '$' sing before flot value

I am looking after quick solution however it is, I can change the logic in the suggested way:

CREATE TABLE #tmpTable(id INT, exposure FLOAT)
INSERT INTO #tmpTable
SELECT 1, 171325.69

SELECT '$ '+cast(exposure AS VARCHAR) Exposure FROM #tmpTable
--OR--
SELECT concat('$ ',exposure) Exposure FROM #tmpTable

DROP TABLE #tmpTable

--Output
Exposure
$ 171326

--Desired
$ 171326.69


I think, the way is not absolute so, please help me on this to resolve.

Answer
CREATE TABLE #tmpTable(id INT, exposure NUMERIC(18,2))
INSERT INTO #tmpTable
SELECT 1, 171325.69

SELECT '$ '+cast(exposure AS VARCHAR) Exposure FROM #tmpTable
--OR-- 
SELECT concat('$ ', exposure) Exposure FROM #tmpTable

DROP TABLE #tmpTable

Having your table as NUMERIC will solve your problem and return the expected result using both methods.

Comments