Results 1 to 6 of 6

Thread: Extracting text from String?

  1. #1
    Join Date
    Mar 2010
    Posts
    3

    Extracting text from String?

    I want to be able to pull text from this string:

    DABLennon,JohnDAQ1466 N Beatles AveDAL

    =========================== ===========

    Basically I want to be able to pull Lennon, John and put that into a FULL_NAME field & pull 1466 N Beatles Ave and put that into a field for address. Can anyone help me? Or point me in the right direction on how to do this?

    I am using SQL Server 2005 on Windows XP

  2. #2
    Join Date
    Mar 2010
    Posts
    3
    any ideas guys?

  3. #3
    Join Date
    Sep 2002
    Posts
    5,938
    Can try with charindex and patindex function if string has certain pattern.

  4. #4
    Join Date
    Mar 2010
    Posts
    3
    I am new to SQL. How do I use the functions? Is there a video tutorial online that can show me?

  5. #5
    Join Date
    Sep 2002
    Posts
    5,938
    Read books online, has sample code in it.

  6. #6
    Join Date
    Jul 2014
    Posts
    1

    Red face Extracting text from String?

    Declare @Str As varchar(500)
    Declare @Name As varchar(500)
    Declare @Address As varchar(500)

    Set @str ='DABLennon,JohnDAQ1466 N Beatles AveDAL'

    Select @str = SUBSTRING(@str,CHARINDEX('DA',@str)+3,LEN(@str))
    Select @Name = SUBSTRING(@str,1, CHARINDEX('DA',@str)-1)
    Select @Name AS FULL_NAME

    Select @str = SUBSTRING(@str,CHARINDEX('DA',@str)+3,LEN(@str))
    Select @Address = SUBSTRING(@str,1, CHARINDEX('DA',@str)-1)
    Select @Address As Address

Tags for this Thread

Posting Permissions

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