By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,461 Members | 1,002 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,461 IT Pros & Developers. It's quick & easy.

Strip out part of a text field in sql 2008 to leave the required part only

P: 1
How can you remove a part of a text field in sql but leave the section that is needed such as
Expand|Select|Wrap|Line Numbers
  1. the cat went up the hill: the dog followed on behind    the mouse went the other way
(4 spaces between 'behind' and 'the mouse')

'the cat followed on behind' is the only bit I need

Also need to add that the text field varies in length so need to use ':' and ' the mouse' to identify the beginning and end
Oct 21 '13 #1
Share this Question
Share on Google+
2 Replies


Rabbit
Expert Mod 10K+
P: 12,430
You can use the CHARINDEX function to find the location of those strings and the SUBSTRING function to extract the parts you need.
Oct 21 '13 #2

P: 2
Expand|Select|Wrap|Line Numbers
  1. DECLARE @X NVARCHAR(MAX) = 'the cat went up the hill: the dog followed on behind the mouse went the other way'
  2.  SELECT SUBSTRING(@X,0,8)+ SUBSTRING(@X,33,20)+ ': '+SUBSTRING(@X,55,9)
Something like that?
Oct 30 '13 #3

Post your reply

Sign in to post your reply or Sign up for a free account.