Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Finding multiple hashtags in one record

$
0
0

All,

I think I'm close (perhaps not) to getting my desired output. I want to parse out, into separate records, the string immediately following a hashtag.

Here is my example:

--DROP TABLE #NUMS
CREATE TABLE #nums (n INT)
DECLARE @i INT 
SET @i = 1
WHILE @i < 50 
BEGIN
    INSERT #nums VALUES(@i)
    SET @i = @i + 1
END
--drop table #tmp
create table #tmp 
( words text)
insert into #tmp
select 
'test #this out please, oh wait here is #another one'
select SUBSTRING(words,n,nullif(charindex('#',words,N),'')-N) as word
from #tmp,#nums
where n <= LEN(cast(words as varchar(max))) 
and SUBSTRING(words,n-1,1) = '#'
and CHARINDEX('#',words,n)-n>0
/*Desired output*/
---- this
---- another

The query above seems to stop @ the first hashtag and right before the second one. It's been a long day so please pardon the lazy code.

Any help would be appreciated. Thanks in advance.


Please 'Mark as Answer' if found helpful - Chris@tier-1-support

Tier 1 Support


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>