0

Need your help again.

Wanted to know is there any way to pass multiple value to single parameter in SQL Server 2012?

For example,

id     item_name  item_code
    1      boots       23
    2       hat        5
    3      dress       11

Let's say in the case above, I have parameter @inp_code

What to do, so when I will pass '23' and '11' to the parameter so I could get the output below:

id      item_name   item_code
   1       boots        23
   3       dress        11
3
  • 1
    a quick search would reveal table valued parameters... Commented Apr 1, 2013 at 8:45
  • how can use it? dont understand( Commented Apr 1, 2013 at 8:54
  • how about doing some (any) research? Just a few minutes worth? What did you find when you typed "sql server 2012 table valued parameters" in a search engine??? Commented Apr 1, 2013 at 9:08

1 Answer 1

1

Here is a link to the MSDN documentation

The overall concept is this.

  1. You'll create a new table type (listed in SSMS under /Programmability/Types/User-Defined Table Types. This will look like a normal SQL table, except the header is different (CREATE TYPE AS TABLE instead of CREATE TABLE)
  2. Once the table type is created, you can define a parameter on your stored proc of the table type.
  3. In a SQL Script, you define a variable of the table type, INSERT into it, and pass it to the stored proc.
  4. Inside you stored proc, you can now access the parameter like a table (meaning it is a rowset, not a single value, so think set-based, not single value)

One item of note - these are not supported via ADO.NET directly. You would need to create a script that would insert multiple values into the table variable, passing that to the stored proc, and execute the entire script from within your programming language.

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

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.