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 > Splitting a combined field

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-04-06, 13:20
rguy84 rguy84 is offline
Registered User
 
Join Date: Jun 2004
Location: Seattle, WA
Posts: 601
Splitting a combined field

In the past I made a query that took employee names (each sperate field) combined them so they displayed Last, First Middle in the query view. I haven't done any work in months, so I am slipping.

Thanks
__________________
Ryan
My Blog
Reply With Quote
  #2 (permalink)  
Old 08-04-06, 14:19
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,605
Is there a question lurking in there somewhere?

-PatP
Reply With Quote
  #3 (permalink)  
Old 08-04-06, 15:00
rguy84 rguy84 is offline
Registered User
 
Join Date: Jun 2004
Location: Seattle, WA
Posts: 601
haha Pat. Basically how do I do it.
__________________
Ryan
My Blog
Reply With Quote
  #4 (permalink)  
Old 08-04-06, 17:58
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,605
Quote:
Originally Posted by rguy84
haha Pat. Basically how do I do it.
Usually you take her out a couple of times, then...

Wait a second... Do what?

Seriously, I don't understand what you're asking me how to do, so I don't have a clue how to help you do it. Keep in mind that I'm an old phart, you need to kind of point me in the right direction before I get a good grip on things.

-PatP
Reply With Quote
  #5 (permalink)  
Old 08-06-06, 08:09
Jugular Bean Jugular Bean is offline
Registered User
 
Join Date: Jul 2006
Posts: 11
The question IS highly ambiguous? Do you want to split a name field that stores first middle and last names, or do you have three fields and you want to combine them?
Reply With Quote
  #6 (permalink)  
Old 08-07-06, 01:23
Littlefoot Littlefoot is offline
Lost Boy
 
Join Date: Jan 2004
Location: Croatia, Europe
Posts: 3,629
But you do have a backup of that ancient query ... somewhere ... don't you? Obviously not

As I understand it, you want something like this (based on Oracle):
Code:
SQL> CREATE TABLE NAMES
  2  (first    VARCHAR2(20),
  3   middle   VARCHAR2(20),
  4   last     VARCHAR2(20)
  5  );

Table created.

SQL>
SQL> INSERT INTO NAMES (first, middle, last) VALUES ('Guy', 'R', 'Eightyfour');

1 row created.

SQL>
SQL> SELECT * FROM NAMES;

FIRST                MIDDLE               LAST
-------------------- -------------------- --------------------
Guy                  R                    Eightyfour

SQL>
SQL> SELECT last ||', '|| first ||' '|| middle ||'.'
  2  FROM NAMES;

LAST||','||FIRST||''||MIDDLE||'.'
----------------------------------------------------------------
Eightyfour, Guy R.

SQL>
Basically, you'll need a concatenation operator - || in Oracle, might be something different in your database.
Reply With Quote
  #7 (permalink)  
Old 08-09-06, 18:37
rguy84 rguy84 is offline
Registered User
 
Join Date: Jun 2004
Location: Seattle, WA
Posts: 601
Okay I have a query that shoots out
PatPhelan
I wan't it to add a space
__________________
Ryan
My Blog
Reply With Quote
  #8 (permalink)  
Old 08-09-06, 18:38
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
Code:
select left('PatPhelan',3) + ' ' + right('PatPhelan',6) as newcolumn
and you will, of course, need to know where to insert the space on every name

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #9 (permalink)  
Old 08-10-06, 12:19
rguy84 rguy84 is offline
Registered User
 
Join Date: Jun 2004
Location: Seattle, WA
Posts: 601
Yes, can't you do like
Code:
SELECT tblPeople.FirstName and tblPeople.LastName AS firstlast
FROM tblPeople
(SELECT left([firstlast], tbl.People[FirstName])+ ' ' 
+ right([firstlast], tbl.People[LastName]);
__________________
Ryan
My Blog
Reply With Quote
  #10 (permalink)  
Old 08-10-06, 12:41
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
would you mind just quickly explaining again what it is you're actually trying to do?
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #11 (permalink)  
Old 08-10-06, 13:15
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,605
From your combined posts, I think I can figure out what you're trying to get to. My best guess is something like:
Code:
SELECT
   first_name + ' ' + last_name -- 'John Doe'
,  last_name + ', ' + first_name + ' ' initial + '.' -- 'Doe, John A.'
   FROM tblPeople
-PatP
Reply With Quote
  #12 (permalink)  
Old 09-01-06, 15:34
rguy84 rguy84 is offline
Registered User
 
Join Date: Jun 2004
Location: Seattle, WA
Posts: 601
Rudy, I want to make a query that takes two fields and slaps them together into one field in a temp table with a bit of formatting
__________________
Ryan
My Blog
Reply With Quote
  #13 (permalink)  
Old 09-01-06, 15:58
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
thank you, ryan, for the very flexible requirements

Code:
select slap_together(one_field,two_field) as new_field
     , format(bit_field,'X') as blue_field
  into temp_table
  from your_table
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #14 (permalink)  
Old 09-06-06, 17:08
rguy84 rguy84 is offline
Registered User
 
Join Date: Jun 2004
Location: Seattle, WA
Posts: 601
the slap_together() concerns me...
__________________
Ryan
My Blog
Reply With Quote
  #15 (permalink)  
Old 09-06-06, 17:23
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
arrrr, as it should, matey!! as it should!!

avast, did ye look it up in yer foine manual, then?



sorry, just practicing ...
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
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