-
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
-
-
Can try with charindex and patindex function if string has certain pattern.
-
I am new to SQL. How do I use the functions? Is there a video tutorial online that can show me?
-
Read books online, has sample code in it.
-
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
-
Forum Rules
|
|