bmw0128
bmw0128

Reputation: 13698

SQL Server trim() Question

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?

Upvotes: 1

Views: 585

Answers (4)

Carls Jr.
Carls Jr.

Reputation: 3078

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)

Upvotes: 0

garyj
garyj

Reputation: 1432

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

Upvotes: 0

Ben Hoffman
Ben Hoffman

Reputation: 8261

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.

Upvotes: 2

rfonn
rfonn

Reputation: 2221

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

Upvotes: 1

Related Questions