简体   繁体   中英

Change the Conditionally formatted numbers into decimal(30,2) in sql server

How to change the (30,45,123.12) to -3045123.12 in SQL Server while before inserting in table? I am facing issue while converting the data.

SELECT CASE 
        WHEN Try_Convert(BIGINT, replace(nullif([numbersvalue], ''), ',', '')) IS NOT NULL
            THEN CONVERT(BIGINT, replace(nullif([numbersvalue], ''), ',', ''))
        ELSE 0
        END
FROM tables

You can use try_convert(money, ... ) It tends to be a little more forgiving

Example

Select try_convert(money,replace(replace('(30,45,123.12)','(','-'),')',''))

Returns

-3045123.12

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM