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. 3 5979
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
....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.
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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Robin Tucker |
last post by:
My code prints out 0 for the value of charindex ( 'Hello.', '.' ).
Did I miss something? I think it should print out 6!
|
by: M Wells |
last post by:
Hi All,
Just wondering if it's any more efficient to use the following SQL
statement to return a partial match from a column as opposed to the
second statement.
SELECT * FROM Table1 WHERE...
|
by: Little PussyCat |
last post by:
Hello,
I need to be able to replace only the first occurance of a space character
in a column.
Reason being is the data in the column I am trying to replace seems to have
umpteen space...
|
by: Willem |
last post by:
Hello
I am quite hopeless and of course a newbe.
The situation: Sql2k / query
I would like it ot break down the following string:
2004 Inventory:Ex.Plant Farm1:1st Cut:Premium:0094
|
by: prav78 |
last post by:
hi there
i have a field name(fil_srt_cond) with the values of
cmpnt_name,ASC,1,2
cmpnt_stuff,DESC,2,3
i used the char index:-
...
|
by: db55 |
last post by:
This script doesn't work. Why?
UPDATE
SET = LTRIM(SUBSTRING(, 1,
convert(bigint, CHARINDEX(',', Comments)-1)))
WHERE NOT( IS NULL) AND LEN() > 8
Basically, I'm trying to...
|
by: matthewwhaley |
last post by:
What is the best way to essentially use the charindex(find) function
if the value is could be more than one variable (A or B or C)
I can't seem to get an "or", "if" or "select if" to work
...
|
by: iritchie |
last post by:
Hello all,
I am trying to write a script which breaks down a single address field into individual fields, with char(10) or a carriage return as the delimiter.
"empltable" is the table I am...
|
by: jeremy |
last post by:
Hello,
I was hoping someone could help me with this SQL statement.
The column 'options.optionDescrip' is a varchar field.
Some values of the 'options.optionDescrip' contain commas, some do...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |