Skip to content
Advertisement

How to pivot given string by replacing special characters in SQL?

In an interview, I have been asked to pivot a string by replacing special characters.

Given string was 'AAA%BBB$CCC#DDD'

Expected output as shown in then image:

Expected Output

How can we do this in SQL Server? Thanks in advance!

Advertisement

Answer

In SQL Server 2014?(I guess the operating system you are using is Windows Server 2008 R2, hahaha), if you use SQL Server 2014-, basically, you need to unify the different separators first,

then like this:

OR

OR

OR

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement