If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > Sorry guys I have to reask.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-15-04, 18:55
rguy84 rguy84 is offline
Registered User
 
Join Date: Jun 2004
Location: Seattle, WA
Posts: 601
Sorry guys I have to reask.

I think I posted this here or in the Access forum, but can't find it. Anyhow in an excel sheet names were entered as Last, First, Middle Int in a single field. I need to split that up into a field for each. Any ways i can cut them up? Like a trim to first comma, then the second. Thanks.
Reply With Quote
  #2 (permalink)  
Old 07-16-04, 03:31
Littlefoot Littlefoot is offline
Lost Boy
 
Join Date: Jan 2004
Location: Croatia, Europe
Posts: 3,629
I don't use Access, but the principle should be the same: you'll have to use a SUBSTRING function combined with a function that'll calculate position of delimiters (comma, space or whatever) and (eventually) length of a string.

In Oracle, those functions are:
SUBSTR(string, starting position, length)
INSTR(string, substring you're looking for, starting position, occurrence)
LENGTH(string)

So, for example:
Code:
CREATE TABLE a (dugo varchar2(20));
INSERT INTO a VALUES ('John M. Doe');
First (John), Middle (M.) and Last (Doe) name would then be:
Code:
SELECT SUBSTR(dugo, 1, INSTR(dugo, ' ', 1, 1) - 1) name FROM a;

SELECT SUBSTR(dugo, INSTR(dugo, ' ', 1, 1), 
              INSTR(dugo, ' ', 1, 2) - INSTR(dugo, ' ', 1, 1)
			 ) middle FROM a;
  
SELECT SUBSTR(dugo, INSTR(dugo, ' ', 1, 2), LENGTH(dugo)) last FROM a;
Reply With Quote
  #3 (permalink)  
Old 07-16-04, 11:20
rguy84 rguy84 is offline
Registered User
 
Join Date: Jun 2004
Location: Seattle, WA
Posts: 601
Thanks! But can anybody chime in how I can pop that into Access or excel?
__________________
Ryan
My Blog
Reply With Quote
  #4 (permalink)  
Old 07-16-04, 14:02
rguy84 rguy84 is offline
Registered User
 
Join Date: Jun 2004
Location: Seattle, WA
Posts: 601
I found this, but dont know how to apply it.
__________________
Ryan
My Blog
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On