469,299 Members | 2,069 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,299 developers. It's quick & easy.

CHARINDEX

SQL Server 2000

Ya know, it is always the simplest stuff that gets ya !!

I am having the hardest time getting a simple piece of code working.
Must be brain dead today.

Goal: Get the users full name from a string

Here is sample data:

"LDAP://blahblahblah/CN=Kevin Jones,OU=DevEng,DC=nobody,DC=priv,DC=com"

Code:
IF LEN(@strReturnValue) > 0 BEGIN
SELECT @strReturnValue = SUBSTRING(@strReturnValue,
(CHARINDEX('CN=',@strReturnValue)+3),
(CHARINDEX(',',@strReturnValue)-1))
END

It will extract:
"Kevin Jones,OU=DevEng,DC=nobody,DC=priv,DC=com"

I want it to extract:
Kevin Jones

Thanks.

Jul 23 '05 #1
3 5725
On 23 Jun 2005 08:51:27 -0700, cs******@dwr.com wrote:
"LDAP://blahblahblah/CN=Kevin Jones,OU=DevEng,DC=nobody,DC=priv,DC=com"

Code:
IF LEN(@strReturnValue) > 0 BEGIN
SELECT @strReturnValue = SUBSTRING(@strReturnValue,
(CHARINDEX('CN=',@strReturnValue)+3),
(CHARINDEX(',',@strReturnValue)-1))


declare @test varchar(255)
declare @pos int

select @test = 'LDAP://blahblahblah/CN=Kevin
Jones,OU=DevEng,DC=nobody,DC=priv,DC=com'
select @pos = CHARINDEX('CN=',@test)+3

SELECT SUBSTRING(@test, @pos , (CHARINDEX(',',@test)) - @pos)
Tony
--
http://www.dotnet-hosting.com
Free web hosting with ASP.NET & SQL Server
No ads - No trials - Innovative features
Jul 23 '05 #2
....oops i should have written:

You're thinking the substring syntax is
substring( string, start, end )

when the correct syntax is
substring( string, start, length )

where length is end_position - start position

Sorry for the confusion.

hth,

victor dileo

cs******@dwr.com wrote:
SQL Server 2000

Ya know, it is always the simplest stuff that gets ya !!

I am having the hardest time getting a simple piece of code working.
Must be brain dead today.

Goal: Get the users full name from a string

Here is sample data:

"LDAP://blahblahblah/CN=Kevin Jones,OU=DevEng,DC=nobody,DC=priv,DC=com"

Code:
IF LEN(@strReturnValue) > 0 BEGIN
SELECT @strReturnValue = SUBSTRING(@strReturnValue,
(CHARINDEX('CN=',@strReturnValue)+3),
(CHARINDEX(',',@strReturnValue)-1))
END

It will extract:
"Kevin Jones,OU=DevEng,DC=nobody,DC=priv,DC=com"

I want it to extract:
Kevin Jones

Thanks.


Jul 23 '05 #3
Note the charindex syntax:
charindex ( string, start, length )

You're mistakenly thinking the syntax is:
charindex ( string, start, end )

The "end" parameter should actually be length from the "start"
position, and be calculated as something like:
length = end - start

Once you fix that, I think your code will work just fine.

hth,

victor dileo

cs******@dwr.com wrote:
SQL Server 2000

Ya know, it is always the simplest stuff that gets ya !!

I am having the hardest time getting a simple piece of code working.
Must be brain dead today.

Goal: Get the users full name from a string

Here is sample data:

"LDAP://blahblahblah/CN=Kevin Jones,OU=DevEng,DC=nobody,DC=priv,DC=com"

Code:
IF LEN(@strReturnValue) > 0 BEGIN
SELECT @strReturnValue = SUBSTRING(@strReturnValue,
(CHARINDEX('CN=',@strReturnValue)+3),
(CHARINDEX(',',@strReturnValue)-1))
END

It will extract:
"Kevin Jones,OU=DevEng,DC=nobody,DC=priv,DC=com"

I want it to extract:
Kevin Jones

Thanks.


Jul 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by M Wells | last post: by
2 posts views Thread by Little PussyCat | last post: by
5 posts views Thread by Willem | last post: by
1 post views Thread by jeremy | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Geralt96 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.