Hello all this is my first post.
I am trying to strip some unwanted text from a column containing department names.
This first query strips all characters after the colon in the name:
The second query strips the prefix from the name:
Both of these work great independent of each other, but when I try to combine them it fails.
I could really use some guidance with this.
Thanks in advance.
I am trying to strip some unwanted text from a column containing department names.
This first query strips all characters after the colon in the name:
Code:
SELECT CASE WHEN CHARINDEX(':', DB.Table.DEPT)>0 THEN LEFT(DB.Table.DEPT, CHARINDEX(':', DB.Table.DEPT)-1) ELSE DB.Table.DEPT END FROM DB.Table
Code:
SELECT REPLACE( REPLACE( REPLACE (DB.Table.DEPT,'[NA1] ','') ,'[NA2] ', '') ,'[NA3] ', '') FROM DB.Table
Code:
SELECT CASE WHEN CHARINDEX(':', DB.Table.DEPT)>0 THEN LEFT(DB.Table.DEPT, CHARINDEX(':', DB.Table.DEPT)-1) ELSE DB.Table.DEPT END FROM (SELECT REPLACE( REPLACE( REPLACE (DB.Table.DEPT,'[NA1] ','') ,'[NA2] ', '') ,'[NA3] ', '') FROM DB.Table)
Thanks in advance.
Comment