Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
thottle
Starting Member
2 Posts |
Posted - 2011-07-01 : 14:10:50
|
Hello,Parsing strings has never been my strong suit. I have a system that pulls data in from Active Directory to update some of the user data.I would like to turn this:CN=Nurse Goodbody,OU=Henry Jekyll MD,OU=Remote Clients,DC=ourServer,DC=localinto this:Henry Jekyll MDwhen it gets imported. I know it's a comma delimited field, but how to extract that out escapes me at the moment.Thanks,Tom Hottle |
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2011-07-01 : 14:41:12
|
Try this:declare @s varchar(200)set @s = 'CN=Nurse Goodbody,OU=Henry Jekyll MD,OU=Remote Clients,DC=ourServer,DC=local'select left(substring(@s, charindex('OU=', @s) + 3, 200), charindex('OU=', substring(@s, charindex('OU=', @s) + 3, 200)) - 2)Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Subscribe to my blog |
|
|
thottle
Starting Member
2 Posts |
Posted - 2011-07-07 : 11:08:15
|
quote: Originally posted by tkizer Try this:declare @s varchar(200)set @s = 'CN=Nurse Goodbody,OU=Henry Jekyll MD,OU=Remote Clients,DC=ourServer,DC=local'select left(substring(@s, charindex('OU=', @s) + 3, 200), charindex('OU=', substring(@s, charindex('OU=', @s) + 3, 200)) - 2)Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Subscribe to my blog
Somewhat close to what I'm doing. I found we had a udf that parsed out the line character by character when called that functions along the same lines, primarily for comma delimited strings.However, what you showed is almost exactly how I wound up doing the cleanup work on the strings to get rid of some ratty data.Thanks!Tom |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
|
|
|
|