September 23, 2014 at 1:20 pm
Hi,
TableA
Col1
----
13.4
13.4 a
13..4
13,.4
Result for Table A needed:
Col1 ColCalculated
--------------------------
13.4 13.4
13.4 a null
13..4 null
13,.4 null
Please let me know how can I achieve it.
Thanks in advance.
September 23, 2014 at 1:44 pm
In SQL Server 2012, you can use TRY_PARSE(), TRY_CONVERT() or TRY_CAST().
September 23, 2014 at 2:16 pm
Simple and maybe not perfect approach is like Luis mentioned, using try_parse. The drawback is that some unwanted values may parse but then again, that might be fine.
😎
;WITH TableA(Col1)
AS (SELECT * FROM (VALUES
('13.4' )
,('13.4 a' )
,('13..4' )
,('13,.4' )) AS X(Col1))
SELECT
TA.Col1
,TRY_PARSE(TA.Col1 AS DECIMAL(12,2)) AS CalculatedColumn
FROM TableA TA
Results
Col1 CalculatedColumn
------ -----------------
13.4 13.40
13.4 a NULL
13..4 NULL
13,.4 13.40
September 23, 2014 at 2:25 pm
Great 🙂
Thanks
Viewing 4 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply