简体   繁体   中英

Replacing a trailing '-' with a leading '-'

I received a csv file (2.6M records) with some values in an hours amount field and a dollars amount field that have a trailing '-' to represent a negative adjustment. I'm trying to figure out a way to move the trailing '-' to a leading '-' so I can set the data type to a numeric value. Replace sounded like a good option however without using wildcards it really isn't as there are thousands of different amounts. Any help would be appreciated. Samples below... 4982.01- 165.48- 0.01- 159.92- 1532.70- 156.38- 766.50- 144.58-

You may try the following update:

UPDATE yourTable
SET col = '-' + SUBSTRING(col, 1, LEN(col) - 1)
WHERE col LIKE '%-';

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