0

I have this column:

floor
---------
dep:first
dep:second
dep:third
dep:fourth

And I want to make it like this :

DEP
------
first
second
third
fourth

I am trying this :

select
    max(case when floor = 'dep:first' then 'first' end) DEP,
    max(case when floor = 'dep:second' then 'second' end) DEP,
    max(case when floor = 'dep:third' then 'third' end) DEP,
    max(case when floor = 'dep:fourth' then 'fourth' end) DEP,
from 
    db.table

But the result returns the DEP column 4 times:

DEP    |DEP    |DEP     |DEP    |
-------|-------|--------|-------|
first  |second |third   |fourth |
0

1 Answer 1

1

How about just using replace() or stuff()?

select replace(floor, 'dep:', '')

or:

select stuff(floor, 1, 4, '')
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for your quick response. I thought too the first option but I wanted to see the one that I asked. Can you please explain me the second option you have provided?
The documentation explains how the function works, @Thkas . STUFF (Transact-SQL)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.