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
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