Loop string and update table

Could you show me how to split @username (by ',') and update table for each item in sql.

Declare @username varchar(100)
set @username = 'Jim, 'John, 'Dave'

Update table set username = ? where user = @username
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

VBdotnet2005Author Commented:
Any thoughts Experts?
you can have a where clause like

where user in ('Jim, 'John, 'Dave')

Open in new window

what probably is what you intend to do.

however the update table statement doesn't make any sense cause you rarely want to update the user name to a value it already has (since you searched for it).

x-menIT super heroCommented:
Declare @username varchar(100)
set @username = 'Jim, John, Dave'

declare @u varchar(max)
while charindex(',',@username) > 0
      set @u = substring(@username,0,charindex(',',@username))      
      SET @username = LTRIM(STUFF(@username,1,len(@u)+1,''))
      Update table set username = ? where user = @u

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Protecting & Securing Your Critical Data

Considering 93 percent of companies file for bankruptcy within 12 months of a disaster that blocked access to their data for 10 days or more, planning for the worst is just smart business. Learn how Acronis Backup integrates security at every stage

dsackerContract ERP Admin/ConsultantCommented:
Please provide more information.
your string looks funny
Craig WagnerSoftware ArchitectCommented:
Why is "Visual Basic.NET" one of the topics on this question? It appears to be a pure SQL question. Or are you looking to do it either in SQL or VB.NET?
VBdotnet2005Author Commented:
thanks x-men, this is exactly what I was looking for.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2008

From novice to tech pro — start learning today.