I have have to compare two char(4)
, which are formatted differently. Thus I would like to one format so that it can be compared to the other. Basically I need to remove prefixed zeros and trailing space if present.
For instance:
The chars:
'001 '
and '1'
should both compare to '1'
after formatting
'001A'
and '1A'
should both compare to '1A'
after formatting
'010 '
and '10'
should both compare to '10'
after formatting
'010A'
and '10A'
should both compare to '10A'
after formatting
'100 '
and '100'
should both compare to '100'
after formatting
'100A'
should compare to '100A'
after formatting
select Replace(Ltrim(Replace(Rtrim(@charToBeFormatted), '0', ' ')), ' ', '0')
seems to work, but feels wasteful to replace strings twice and it really does not make the intention clear at all.
Can the result be achieved in a more efficient and/or elegant manner?