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 2005 Forums
 Transact-SQL (2005)
 data within a field

Author  Topic 

alexmarshuk
Starting Member

12 Posts

Posted - 2010-02-11 : 07:51:30
Hi,

I have to write a report which requires me to pull out the server name from within a field. This report is thousands of row so can't do it by hand.

How do I do this in SQL?

An example of the data within the field is:

/O=RCN/OU=CARDIFF/cn=Configuration/cn=Servers/cn=RCN-CARDIFF1/cn=Microsoft Private MDB

I want the report to only display RCN-CARDIFF1 (or equivalent server). /CN= always comes before the server name and after.

thanks,

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-02-11 : 07:58:48
[code]
SELECT SUBSTRING(YouCol,PATINDEX('%Servers/cn=%',YouCol)+11,CHARINDEX('/',YouCol,PATINDEX('%Servers/cn=%',YouCol)+11)-PATINDEX('%Servers/cn=%',YouCol)-11) FROM YourTable
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-02-11 : 08:02:28
Also read
http://beyondrelational.com/blogs/madhivanan/archive/2009/11/18/parsing-a-string.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -