Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Last name and first name string 1

Status
Not open for further replies.

kevinluebb

Programmer
Jan 4, 2002
30
0
0
US
Ok now I know I know this and it's buried deep in my head somewhere but for the life of me I can't think of it.

I've got a field in a table where the last name and first name are together (ie... Smith/John) note the slash. I want to put last name and first name in different fields for comparison. I know it's easy and I've done it before
 
Here is what I came up with. There may be something much
easier (I tend to go the hard way):

create table test1 (fullname varchar(128))

insert into test1 values ('Smith/John');

SELECT
SUBSTRING(fullname,CHARINDEX('/',fullname)+1,128) as Fname,
SUBSTRING(fullname,1,CHARINDEX('/',fullname)-1) as Lname
from Test1
 
Not what I remember but I'll sure give it a shot. Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top