Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Returning a value in between two specific strings

Author  Topic 

LampCommandr
Starting Member

1 Post

Posted - 2011-08-08 : 16:15:29
Hey folks,

I’m attempting to parse out the string in a column to return the strings in between the characters "1. " and "2. ".

The field itself has a values similar to this:

String 1. String String 2. String String String 3. String

Is it possible to extract that data simply on the select or would I need to build a function to accomplish that?

Any help would be appreciated. Thanks in advance!

Ghanta
Yak Posting Veteran

96 Posts

Posted - 2011-08-08 : 16:19:21
use charindex() and substring() functions
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-08-09 : 10:42:06
something like


DECLARE @field varchar(100)
set @field='String 1. String String 2. String String String 3. String'


SELECT RTRIM(RTRIM(SUBSTRING(@field,PATINDEX('%1.%',@field)+2,PATINDEX('%2.%',@field)-PATINDEX('%1.%',@field)-2)))


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -