SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


select between left & right...


select between left & right...

Author
Message
b4better
b4better
SSC Rookie
SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)

Group: General Forum Members
Points: 27 Visits: 52
lets say i have a varchar column such as the following:

The quick brown fox jumps over the lazy dog


i guess using string functions would it be possible to select a space
between 2 words?

for example i just need ' fox ' and not start or the finish of the row.
in fact, in this case to be more precise my column is the same across
all rows, but ' fox ' could be ' tiger ' or ' elephant ' or ' bird ' etc.

so just selecting between 'the quick brown ' and ' jumps over the lazy dog.

ideas?

thanks in advance.
Mohan Kumar
Mohan  Kumar
SSCommitted
SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)

Group: General Forum Members
Points: 1531 Visits: 596
Yes, It is possible to select space between two words.

--www.sqlvillage.com
Matt Miller (4)
Matt Miller (4)
SSChampion
SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)

Group: General Forum Members
Points: 12157 Visits: 18572
I'd look at setting up a CLR function using Regular Expressions. You haven't given me enough to understand why ' fox ' and not any one of the other words; that being said - CLR is in my opinion a far superior string handler to what we have in T-SQL native.

Regex.Match(n) or Regex.Matches could easily return either the nth instance of the pattern, or ALL of the instances of the pattern. Lots of built-in power - might be worth tapping into.

I suspect that you'd get a LOT of mileage out of it. And the VS team at Microsoft spent a lot of time optimizing regular expression performance, so your T-SQL shouldn't really suffer from using it (you may find it's actually faster than trying it with the built-in functions)...

----------------------------------------------------------------------------------
Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?
b4better
b4better
SSC Rookie
SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)

Group: General Forum Members
Points: 27 Visits: 52
ok... great. that gives me a starting point.

appreciate the feedback.
Chandrachurh Ghosh
Chandrachurh Ghosh
Old Hand
Old Hand (347 reputation)Old Hand (347 reputation)Old Hand (347 reputation)Old Hand (347 reputation)Old Hand (347 reputation)Old Hand (347 reputation)Old Hand (347 reputation)Old Hand (347 reputation)

Group: General Forum Members
Points: 347 Visits: 331
Use the following script -

DECLARE @String VARCHAR(255),
@SearchStr VARCHAR(255)
SET @String='The quick brown fox jumps over the lazy dog'
SET @SearchStr='fox '+'////'
SELECT SUBSTRING(@String,CHARINDEX(LEFT(@SearchStr,LEN(@SearchStr)-4),@String),LEN(@SearchStr)-4)

Note: You can directly have the column name in place of the variable.

Chandrachurh Ghosh
DBA – MS SQL Server
Ericsson India Global Services Limited
Quality is not an act, it is a habit.
Chandrachurh Ghosh
Chandrachurh Ghosh
Old Hand
Old Hand (347 reputation)Old Hand (347 reputation)Old Hand (347 reputation)Old Hand (347 reputation)Old Hand (347 reputation)Old Hand (347 reputation)Old Hand (347 reputation)Old Hand (347 reputation)

Group: General Forum Members
Points: 347 Visits: 331
You will not have any problem with prefix blanks, as the LEN function only trims the trailing blanks.....hope this helps

Chandrachurh Ghosh
DBA – MS SQL Server
Ericsson India Global Services Limited
Quality is not an act, it is a habit.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search