3
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

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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....

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.