create proc InsertTagsForArticle(@ArticleID int, @TagIDsList nvarchar(max))
as
--...........
The parameter @TagsList
contains IDs of tags separated by comma: "18,22, 23"
.
How to insert these IDs into table by more rational way?
EDIT: The question is how to insert an array into sql server table, but not how to parse an array. It's something like foreach
operator.
2 Answers 2
As SQL server doesn't support native arrays, there's not much that you can do.
- Serialize this array and store in a field.
- Create child table / relations and store individual records there.
Your requirements will dictate what's better for you. But usually normalized approach is working better.
Comments
You need to use e.g. a user-defined function that splits the comma-separated string into a table - see e.g. here:
SQL Server Helper - Comma-Delimited Value to Table
or many more available on the interwegs - just Google or Bing for "split comma-separated string into table" and you'll have thousands of hits....