Home Loop through words in a string
Reply: 0

Loop through words in a string

user4935
1#
user4935 Published in September 19, 2018, 6:43 pm

I've seen a lot of javascript stack questions around this, but nothing specifically related to SQL Server.

What I need to do is accept a string value and do a loop over the string multiple times to get back all the individual words so I can do calculations on them.

A rough idea is shown below. Anyone know how this can be achieved?

Declare @String nvarchar(50) = 'Mary had a little lamb'
Declare @word nvarchar(50) 

Start Loop 1 to 5 
    Set @word = 'Mary' (1)
    Set @word = 'had' (2)
    Set @word = 'a' (3)
    Set @word = 'little' (4)
    Set @word = 'lamb' (5)
End Loop
share|improve this question
  • 2
    Google: "SQL Server split string". – Gordon Linoff Nov 15 '17 at 0:42

2 Answers 2

active oldest votes
up vote 0 down vote accepted
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.33358 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO