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) |
 |
|
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 |
 |
|
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 MVPhttp://visakhm.blogspot.com/ |
 |
|
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 |
 |
|
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 MVPhttp://visakhm.blogspot.com/ |
 |
|
kkmurthy
Starting Member
41 Posts |
Posted - 2012-03-09 : 12:25:16
|
Yes |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-03-09 : 12:33:05
|
[code]SELECT t.yourfield,f.Val AS DepartmentNameFROM table tCROSS APPLY dbo.ParseValues(STUFF(t.yourfield,1,PATINDEX('%DC=%',t.yourfield)+3,''),',DC=')fWHERE f.ID=3[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
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 |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-03-09 : 21:43:06
|
welcome------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|