Home > database >  Replacing a trailing '-' with a leading '-'
Replacing a trailing '-' with a leading '-'

Time:11-26

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-

CodePudding user response:

You may try the following update:

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