Reputation: 1482
In SQL I have a field that has a lot of text in it.
I am trying to find a way to get text from the field if it contains certain words.
An example:
textField = 'This is the value for your spaceID=12345678'
textField = 'This is the value for your typeID=43254364'
So if the textField
contains spaceID
I want to return the value for it
If textField
like spaceID
then return 12345678
I am just not sure how to return the value of that ID.
Upvotes: 0
Views: 86
Reputation: 50163
You can use substring()
:
select substring(textField, charindex('spaceID=', textfield) + 8, len(textField))
Upvotes: 1
Reputation: 164069
You can do it with substring()
:
select substring(textfield, charindex('spaceID=', textfield) + len('spaceID='), 100)
from tablename
where textfield like '%spaceID=%'
Upvotes: 1
Reputation: 1180
Hi i think thoses example can help you :
declare @value varchar(400)
SET @value = 'This is the value for your spaceID=12345678'
select @value, CHARINDEX('=',@value,1), SUBSTRING(@value,CHARINDEX('=',@value,1) + 1 ,10)
where @value like '%spaceID%'
And see thoses different link :
Upvotes: 1