In my database I have a string that looks like this "P1_123456".
I am splitting the P1_ from the rest with the following:
right([PersNr], charindex('_', reverse([PersNr])) - 1) as PersNr
That leaves me with a single "space" after the last number. How can I prevent that space or remove it? I know how to remove spaces normally but not in combination with what I already have.
PersNritself has any leading and trailing whitespaces in the data. Moreover, you can useLTRIM(RTRIM(RIGHT([PersNr], CHARINDEX('_', REVERSE([PersNr])) - 1))) AS PersNrto trim those left and right unnecessary spaces.replace(value, ' ', '')?