December 9, 2003 at 1:12 pm
Hi,
I have a Manager_Name field which contains first and last name (example: 'Pam Smith').
How can I write a query to list only first name?
Thank you.
December 9, 2003 at 1:20 pm
SELECT LEFT(Manager_Name, CHARINDEX(' ', Manager_Name, 1) -1)
* Noel
December 9, 2003 at 1:22 pm
I bet Jonathan will post PARSENAME stuff.
In the meantime try
SELECT LEFT(your_field,CHARINDEX(' ', your_field))
this assumes that you always have a blank as separator and no leading blanks.
Frank
--
Frank Kalis
Microsoft SQL Server MVP
Webmaster: http://www.insidesql.org/blogs
My blog: http://www.insidesql.org/blogs/frankkalis/[/url]
December 9, 2003 at 1:42 pm
Yup,
SELECT LEFT(your_field,CHARINDEX(' ', your_field,1)-1)
is better
Frank
--
Frank Kalis
Microsoft SQL Server MVP
Webmaster: http://www.insidesql.org/blogs
My blog: http://www.insidesql.org/blogs/frankkalis/[/url]
December 9, 2003 at 2:06 pm
quote:
I bet Jonathan will post PARSENAME stuff.Frank
No, Noel's way is better than PARSENAME for this as it ignores multiple word last names (like mine). Of course, some people down South have multiple word first names.
--Jonathan
--Jonathan
December 10, 2003 at 3:03 am
quote:
Hi,I have a Manager_Name field which contains first and last name (example: 'Pam Smith').
How can I write a query to list only first name?
Thank you.
Btw, any chance to change table design and split the information?
Frank
--
Frank Kalis
Microsoft SQL Server MVP
Webmaster: http://www.insidesql.org/blogs
My blog: http://www.insidesql.org/blogs/frankkalis/[/url]
December 10, 2003 at 8:26 am
quote:
... it ignores multiple word last names (like mine). Of course, some people down South have multiple word first names.--Jonathan
Which is why, when you're asked to do something like this, you make sure you explain what the results will be to the individual motivating the request.
I normally enter "R David" as my first name in forms, and am mildly peeved when that simply gets shortened to "R" (note: I have never lived further south than my current residence of Columbus Ohio 🙂 ).
If a name has three distinct words, all at least two characters long, it is impossible to guess 100% accurately for all valid names the right way to break up the data.
Where can I see ParseName? I'd like to see how others have dealt with the issues involved.
R David Francis
R David Francis
December 10, 2003 at 8:40 am
Jonathan came up with a great solution to a different problem.
Unfortunately I lost track of this thread, but you can always look at BOL
Frank
--
Frank Kalis
Microsoft SQL Server MVP
Webmaster: http://www.insidesql.org/blogs
My blog: http://www.insidesql.org/blogs/frankkalis/[/url]
December 11, 2003 at 2:53 am
Here is the answer to the multiple word firstname problem
declare @name varchar(100)
set @name = 'Marie Sarah Vigote'
SELECT LEFT(@name, LEN(@name)-CHARINDEX(' ', REVERSE(@name), 1))
Of cours is you have a name where you have multiple word first name AND multiple word lastname then you have a problem ...
But I thing it is more frequent to have more the one firstname then more then one lastname (of cours Jonathan is an exception, as usual)
Bye
Gabor
Bye
Gabor
Viewing 9 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply