I have a table with field ID.
Here are some sample values:
- 0001
- 0002
- 990003
- 990004
- 880005
- 880006
- 888006
I have a point where im fetching this records and i need to cut out the 99/88 (well its a pre-known prefix in my case its either 99 or 88 ... keep in mind that a valid id is also lets say 888888 that needs to be converted to 8888!.
I am aware that if all records had leading 99 or 88 i could use:
SELECT RIGHT(MyColumn, LEN(MyColumn) - 2) AS MyTrimmedColumn
How would i include a condition if there is leading 99/88 do the trim else not?
The expected output would be:
- 0001
- 0002
- 0003
- 0004
- 0005
- 0006
- 8006
The function should be part of the select query and not a standalone query (example of the problem - field ID)!
SELECT
ISNULL(ProcId,0) ProcId,
ISNULL(ID,'') ID,
...