Split and Insert comma separated values in database in SQL Server

Last Reply one year ago By Andrea

Posted one year ago

Sir,

there are collections of Ward_id as @wid varchar(max)='2,3,4,5,6,7,8'

I want to save these values in a table having columns as (UserID,district_id,localbody_id,ward_id). 

district_id, localbody_id & user_id would be same with a pair of ward_ids therefore that values should get inserted in table together as a separate row for each.

If there is a sigle wardid then also it should get save...

What should I do to save these data at once. 

I am using SQL SERVER 2012

 

Posted one year ago
Hi @Sumeet,
Please try the following

While loop to insert comma separated values in table in SQL Server

It might help you.

Cheers Andrea.