Results 1 to 2 of 2

Thread: Get names out of a field seperated by a character

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2005
    Posts
    259

    Get names out of a field seperated by a character

    I am working with a table that has names stored like this:

    Dent~Aurthur
    Servo~Tom
    Gently~Dirk

    I need to run a select query that will take the Name field and split it up so that it puts the Authur in a FirstName Field and Dent in the LastName field. Is that possible using a query?

  2. #2
    Addicted Member
    Join Date
    Jul 2006
    Posts
    147

    Re: Get names out of a field seperated by a character

    This is on what database? Anyhow this would work with MS-SQL 2005.

    Table_1 has a column called bah with data like 'Anderson~Mr'
    Table_2 has 2 columns which it inserts the names into.
    SUBSTRING(string,start,end) -- gets you part of a string between end and start
    LEN(string) -- gets you the length of the string

    SQL Code:
    1. INSERT INTO Table_2
    2. SELECT SUBSTRING(bah, CHARINDEX('~', bah) + 1, LEN(bah)) AS Firsty,
    3. SUBSTRING(bah, 1, CHARINDEX('~', bah) - 1) AS lasty
    4. FROM Table_1


    Of course I doubt this would work on anything bar MS-SQL, it does however give you the basic idea of what to do.

    I am not sure if Access etc provide T-SQL, however at the worst you could use ADO to pull out records, split them using VB Mid() etc and insert..
    There is probably a better way then that.
    Me and Access don't get on sorry.
    Last edited by Ishamael; Mar 19th, 2007 at 11:56 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width