I am supporting an ETL process that transforms flat-file inputs into a SqlServer database table. The code is almost 100% T-SQL and runs inside the DB. I do not own the code
While not necessarily the best approach for my situation, I wanted to leave a potential solution for future use that we uncovered while researching this problem.
It appears that the SqlServer datatype MONEY
can be used as a direct cast for strings with a comma separating the non-decimal portion. So, where SELECT CAST('12,345.56' AS DECIMAL(24,10))
fails, SELECT CAST('12,345.56' AS MONEY)
will succeed.
One caveat is that the MONEY
datatype has a precision of 4 decimal places and would require an explicit cast to get it to DECIMAL
, should you need it.