Link to home
Start Free TrialLog in
Avatar of Member_2_7967487
Member_2_7967487

asked on

Remove special characters

Greetings!

I would like some assistance to remove the | sign ONLY, if the Category IDs start with |

Example: Per highlighted screenshot, I would like to remove the | in the front of the column. I would like to leave the | for the rest to help separate the numbers. Thanks!

 User generated image
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

try like:
select *, 
case when charindex('|',CategoryIDs)=1 then substring(CategoryIDs,charindex('|',CategoryIDs)+1,len(CategoryIDs)-1) else CategoryIDs end New_CategoryIDs from Items

Open in new window

or
select *, 
case when charindex('|',CategoryIDs)=1 then substring(CategoryIDs,2,len(CategoryIDs)-1) else CategoryIDs end New_CategoryIDs from Items

Open in new window

I think using left is more effective:
select *, case when left(CategoryIDs,1) <> '|' then CategoryIDs else substring(CategoryIDs,2,8000) end CategoryIDs2 from Items

Open in new window

Please test this in a DEV environment before running in Production:
UPDATE Items
SET CategoryIDs = SUBSTRING (CategoryIDs ,2, LEN(CategoryIDs)-1)  
WHERE LEFT(CategoryIDs,1) = '|'

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Scott Pletcher
Scott Pletcher
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial