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 2008 Forums
 Transact-SQL (2008)
 operation on string help please

Author  Topic 

kkmurthy
Starting Member

41 Posts

Posted - 2012-03-09 : 09:56:10
I have a charater string : 'CN=CHARTWWB01,OU=Workstations,DC=chart_dom,DC=ad,DC=cdot,DC=mdstate'

In the above tring I need to get one result: CHARTWWB01
and other result as: cdot

Can some one please help me using string fuctions just to get this characters only

robvolk
Most Valuable Yak

15732 Posts

Posted - 2012-03-09 : 10:20:59
DECLARE @string varchar(100)='CN=CHARTWWB01,OU=Workstations,DC=chart_dom,DC=ad,DC=cdot,DC=mdstate'
SELECT SUBSTRING(@string, CHARINDEX('=', @string) + 1, CHARINDEX(',', @string) - CHARINDEX('=', @string) - 1)
Go to Top of Page

kkmurthy
Starting Member

41 Posts

Posted - 2012-03-09 : 11:31:31
Thank you. I got this. I am still struggling on getting cdot from the above string
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-03-09 : 11:37:02
whats the criteria for your result? you've multiple DC values coming so whats rule for selecting cdot alone? is it always 3rd occurance you want?

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

Go to Top of Page

kkmurthy
Starting Member

41 Posts

Posted - 2012-03-09 : 11:41:53
I want to pickup cdot which appears after third 'DC=' occurance. I will be pickeing dept name (for example cdot)in the query
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-03-09 : 11:48:51
so is it always 3rd DC value you want?

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

Go to Top of Page

kkmurthy
Starting Member

41 Posts

Posted - 2012-03-09 : 12:25:16
Yes
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-03-09 : 12:33:05
[code]
SELECT t.yourfield,f.Val AS DepartmentName
FROM table t
CROSS APPLY dbo.ParseValues(STUFF(t.yourfield,1,PATINDEX('%DC=%',t.yourfield)+3,''),',DC=')f
WHERE f.ID=3
[/code]

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

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-03-09 : 12:33:53
parsevalues function can be found here

http://visakhm.blogspot.com/2010/02/parsing-delimited-string.html

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

Go to Top of Page

kkmurthy
Starting Member

41 Posts

Posted - 2012-03-09 : 13:07:23
Thank you vgery much visakh. I will lok into the function as well
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-03-09 : 21:43:06
welcome

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

Go to Top of Page
   

- Advertisement -