Questions tagged [table-valued-parameters]

Table-Valued Parameters is a feature introduced in SQL SERVER 2008. In earlier versions of SQL SERVER it is not possible to pass a table variable in stored procedure as a parameter, but in SQL SERVER 2008 we can use Table-Valued Parameter to send multiple rows of data to a stored procedure or a function without creating a temporary table or passing so many parameters.

Table-valued parameters are like parameter arrays in OLE DB and ODBC, but offer more flexibility and closer integration with Transact-SQL. Table-valued parameters also have the benefit of being able to participate in set-based operations

Transact-SQL passes table-valued parameters to routines by reference to avoid making a copy of the input data.

http://msdn.microsoft.com/en-us/library/bb510489.aspx

Table-valued parameters are declared by using user-defined table types. You can use table-valued parameters to send multiple rows of data to a Transact-SQL statement or a routine, such as a stored procedure or function, without creating a temporary table or many parameters. Table-valued parameters are like parameter arrays in OLE DB and ODBC, but offer more flexibility and closer integration with Transact-SQL. Table-valued parameters also have the benefit of being able to participate in set-based operations. Transact-SQL passes table-valued parameters to routines by reference to avoid making a copy of the input data. You can create and execute Transact-SQL routines with table-valued parameters, and call them from Transact-SQL code, managed and native clients in any managed language.

411 questions
11
votes
3 answers

Passing Table Valued parameter to stored procedure across different databases

I'm using SQL Server 2008. How can I pass Table Valued parameter to a Stored procedure across different Databases, but same server? Should I create the same table type in both databases? Please, give an example or a link according to the…
hgulyan
  • 8,099
  • 8
  • 50
  • 75
11
votes
3 answers

EntityFrameWork and TableValued Parameter

I'm trying to call a stored procedure from EntityFramework which uses Table-value parameter. But when I try to do function import I keep getting a warning message saying - The function 'InsertPerson' has a parameter 'InsertPerson_TVP' at …
10
votes
1 answer

CLR Table-valued function with array argument

I have a SQL CLR function like this one: public partial class UserDefinedFunctions { [Microsoft.SqlServer.Server.SqlFunction(TableDefinition = "number int", FillRowMethodName = "FillRow")] public static IEnumerable MyClrFunction(object obj)…
10
votes
2 answers

Pass test data to table-valued parameter within SQL

Is it possible, and if so how, to pass data to a table-valued parameter of a stored function using SQL EXEC? I know how to pass in data from C#. One of my four stored procs using table-valued parameters is not producing the expected results. I'd…
Randy Hall
  • 7,716
  • 16
  • 73
  • 151
10
votes
1 answer

DataTable with a byte[] field as parameter to a stored procedure

I've been reusing this method of using a DataTable as a parameter to a stored procedure and it's been working great. This is the simplified working code: using (dbEntities dbe = new dbEntities()) { var dt = new dataTable(); …
kei
  • 20,157
  • 2
  • 35
  • 62
9
votes
3 answers

Is it safe to reuse a SqlDataRecord?

When implementing table-valued parameters, one of the most common ways to generate an IEnumerable for use by the parameter is code like this (e.g., https://stackoverflow.com/a/10779567/18192 ): public static IEnumerable
Brian
  • 25,523
  • 18
  • 82
  • 173
9
votes
2 answers

How to set up ASP.NET SQL Datasource to accept TVP

In the codebehind you would add the TVP as a SqlDbType.Structured for a stored procedure But this doesn't exist in an ASP.NET SqlDataSource control. I have stored my Datatables in session variables (don't worry they are small!) and I need to pass…
Matthew
  • 10,244
  • 5
  • 49
  • 104
9
votes
2 answers

What permission do I need to use an SQL Server Table Valued Parameter (TVP) as a stored proc parameter?

I'm using SQL Server 2008 R2 and I've created a TVP that I want to use as a parameter to a stored proc but I get a message saying that it can't be found or I don't have permission. I can use the TVP in a script or in the body of the stored proc, but…
8
votes
3 answers

Is the sort-order of table-valued-parameters guaranteed to remain the same?

I need to know if i need to add a sort-column to my custom table-type which i could then use to sort or if i can trust that the order of parameters remains the same even without such a column. This is my type: CREATE TYPE [dbo].[VwdCodeList] AS…
Tim Schmelter
  • 450,073
  • 74
  • 686
  • 939
8
votes
4 answers

Table-Valued Parameter in Stored Procedure and the Entity Framework 4.0

I have a stored procedure in SQL Server 2008 called 'GetPrices' with a Table-Valued Parameter called 'StoreIDs'. This is the type i created for this TVP: CREATE TYPE integer_list_tbltype AS TABLE (n int) I would like to call the SP from my Entity…
8
votes
3 answers

Should I have a Primary Key on User Defined Table Types?

Firstly, I understand the role of Primary Keys on tables in SQL, or any database for that matter. However, when it comes to user-defined table types, I find myself unable to see why I should create a Primary Key. In my experience I've found no…
Jon Bellamy
  • 3,333
  • 20
  • 23
8
votes
1 answer

Pass table value param to stored procedure using PetaPoco

For while I am trying to call SQL Server 2008 R2 stored procedure using PetaPoco. My stored procedure accepts a table valued parameter. How I can call the stored procedure in petapoco with table value param? Here what I am trying to do: var db =…
7
votes
1 answer

Accessing stored procedures with robconery / massive?

Another great article by Rob on the Massive ORM. What I haven't been able to find is references on how to access stored procedures. SubSonic had some issues with the overhead of using ActiveRecords, so I preferred to do data access with stored…
7
votes
0 answers

How can i use a TVP in an EF6 query? (not a stored proc)

I'm having SQL performance issues on Azure with complex EF6 queries. The environment is configured as an elastic pool. In the development area, the eDTU limit is hit frequently via CPU usage which I have attributed to query plan generation. The…
7
votes
2 answers

Passing a table as an input parameter to Dapper in .NET Core

While trying to pass a table in as a parameter to a stored procedure via Dapper, I came across this SO answer, which indicates that it is directly supported in Dapper. In .NET core however, DataTable seems not to be implemented, so this does not…
Kjartan
  • 18,591
  • 15
  • 71
  • 96
1
2
3
27 28