Home > OS >  Removing a specific part of a string
Removing a specific part of a string

Time:09-22

I've got a dataset of asset. Every asset has a unique code which ends ALWAYS with '_ISP'. I need to export the dataset to Excel but I need to remove the '_ISP' from the code. I've tried with the function TRIM and RTRIM but they don't allow me to use the field name, also tried the SUBSTRING function but asset codes don't always have the same lenght. Any advice? This is what I have:

|asset_code|
|AAAAA_ISP |
|BBB_ISP   |

and this is what I need to export:

|asset_code|
|AAAAA     |
|BBB       |

Thank you :)

CodePudding user response:

Use replace() to replace '_ISP' with blank, effectively deleting it:

select replace(asset_code, '_ISP', '') as asset_code
from mytable
  • Related