SQLTeam.com | Weblogs | Forums

Separate comma-delimited field into separate fields in T-SQL?


#1

Hello,

Is there a way using T-SQL to separate the values present in a comma-delimited field into separate fields on the same record? I am working with full Distinguished Names of Active Directory Groups, and would like to separate the component parts (CN=, OU=, DC=, etc.). So, for this example: CN=ACL Group,OU=Security Dept,OU=Europe Office,DC=domain1,DC=domain2,DC=com** - this one field would then be written out to 6 columns, instead of all in one. It would write to a new column every time it came to a comma or (preferably), when I encounter a 'CN=' or 'OU=' or 'DC=' substring. I have some slick ways to do this in Excel (in addition to the Text-to-Columns functionality) and would love to know how to do the same within a SQL query.

Thank you!


#2

http://www.sqlservercentral.com/articles/Tally+Table/72993/