tags:

views:

39

answers:

4

I have a varchar field in the database. I want to do a SQL to get the values in the field, and do like a substring on the result. I want to only return the words between some beginning and ending. For instance, for the field value "We few, we happy few.", I want to return only "we happy". Does SQL Server have a function to do this?

+1  A: 

This should be what you are looking for: SubString msdn article.

rfonn
+1  A: 

Your question is a little unclear. Substring will work for this specific case. Check out this msdn article for a list of all of the string functions. From what I can tell you will probably need to use a few in unison.

RandomBen
A: 

I find the page String Functions (Transact-SQL) quite useful when dealing with strings in TransactSQL

garyj
A: 

Hope this will answer your question...

declare @a as varchar(500) set @a='We few, we happy few.' print Substring(@a,charindex('we',@a),2) + ' ' + Substring(@a,charindex('happy',@a),5)