Home > Enterprise >  I need a query result to display values different from what is present in the table
I need a query result to display values different from what is present in the table

Time:07-15

I have table 'EMP' with column 'SerialNumber' and values as S001, S002, S003, S004...till S100. I need the result to display SerialNumber as 001, 002, 003, 004..till 100. How do I write this query?

CodePudding user response:

Here are two ways to do it:

select substr(SerialNumber, 2) as SerialNumber
from emp

OR

select replace(SerialNumber, 'S', '') as SerialNumber
from emp

DEMO

CodePudding user response:

I would use the function REPLACE:

REPLACE( target_column, bad_string, good_string)

Select REPLACE(SerialNumber, 'S', 'Serial Number ') from EMP;

Check this page for how Replace works.

  • Related