Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL Server String Manipulation

Status
Not open for further replies.

SamBones

Programmer
Aug 8, 2002
3,186
US
I have a question about string manipulation in SQL Server. I have more of an Oracle background and can do this in SQL*Plus, but I'm having trouble coming up with a working SQL Server version.

The situation is, I have an application that sits on MS SQL Server. It uses LDAP to authenticate users. The users' LDAP info (distinguishedName) is kept in the database. We recently had a change to our LDAP systems that means we need to change the information in the database to match the new format. We have many thousands of users, so it's too big to be done manually.

What I need is an update command that will change the distinguishedName that is stored as follows...

From: [tt]uid=myuserid,ou=M,ou=xyz,ou=accounts,DC=COMPANYNAME,DC=COM[/tt]

To: [tt]CN=myuserid,OU=MYDOMAIN,OU=Accounts,DC=CompanyName,DC=com[/tt]

That is, I just need to cut out the 'myuserid' and build the new distinguishedName from that. Any help would be appreciated.

I'm still working on it (learning exercise). If I come up with something that looks right to me, I'll post it for critique and comments.

 
Would this cut it?

Code:
UPDATE LDAP_AUTH
SET    distinguishedName = 'CN=' + SUBSTRING(distinguishedName,5,PATINDEX('%,%,distinguishedName)) + ',OU=MYDOMAIN,OU=Accounts,DC=CompanyName,DC=com'
WHERE  somecondition;

Basically I just want that 'uid=' value from the first one. Does this look correct? Am I missing anything?

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top