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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Parsing out AD data to extract field value

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=local

into this:

Henry Jekyll MD

when 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 Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

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 Kizer
Microsoft MVP for Windows Server System - SQL Server
http://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
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-07-07 : 14:16:16
You're welcome, glad to help.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -