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
0
votes
1 answer

Inner join if tables are empty with Top 1000 results

I have three table valued parameters passed into an SP. These all contain data to filter a query. I want to join them to a table as below but only if there is data in a table valued parameter SELECT DISTINCT TOP (1000) Person.col1, …
Richard Watts
  • 954
  • 2
  • 8
  • 21
0
votes
1 answer

Recommendations for storing real-time data that allows for high speed storage/retrieval with .NET API

I am trying to find the best solution to essentially replace a SQL database in a solution that is currently under development, but is working. The data store needs to to include table partitioning and file groups that can be backed up and/or rolled…
Alex
  • 1
0
votes
1 answer

How to access columns and data of a Sql parameter of SqlDbType as Structured in C#?

In C#, for Table-valued parameter I add a SqlParameter with 'SqlDbType' as 'Structured' and 'Value' as a C# DataTable. I want to extract this data later in my code. I want to verify if the SqlDbType/DbType is 'Structured'. If yes, and if the…
0
votes
1 answer

How to pass a user defined table type returned from a function as a parameter to another inline function (without 'DECLARE')?

I'm afraid the answer to this is "NO, you can't", but since I can't find this explained anywhere I'm gonna ask anyway. Given a user defined table type: CREATE TYPE MyType AS TABLE( [Id] UNIQUEIDENTIFIER NOT NULL, [Name] …
Abel
  • 56,041
  • 24
  • 146
  • 247
0
votes
1 answer

Pyodbc Error "A TVP's rows must be Sequence objects.", 'HY000'

I am calling an API and moving the data from json to sql. When I try to post to sql I get this error: Pyodbc Error "A TVP's rows must be Sequence objects.", 'HY000' Here is my SQL Statement in python: conn = pyodbc.connect('Driver={ODBC Driver 17…
0
votes
0 answers

How to pass a df as table-valued parameter, and once df passed as TPV using that update or insert the output table in SQL Server

As part of my development activity in project I need to update or insert the output table. I am trying to pass a DF as table valued parameter in store procedure. By using a stored procedure, I want to achieve this. Could someone please help me…
0
votes
0 answers

Is passing record to SQL Server from external application equally expensive than passing it within the SQL Server

So I have a stored procedure in which I pass user defined table type parameter from my C# web application. I pass thousands of them. Now within the stored procedure I modify this data a bit and so I pass that data to another table valued function.…
0
votes
1 answer

Does FreeTDS ODBC + pyodbc support table-valued parameters (TVPs)?

I'm working on unix/rhel7 system. I have installed require drivers for FreeTDS, unixODBC and pyodbc.Other query is working fine but when I'm trying execute stored proc with TVP (table valued parameter), its giving me error. Is there any way to…
0
votes
1 answer

WHERE IN performs much better with Table Type than with hardcoded values in SQL Server

I have 2 queries that are essentially the same (at least if I didn't miss something). DECLARE @siloIds SiloIdsTableType INSERT INTO @siloIds VALUES (1),(2),(3) -- Query 1 SELECT * FROM [Transaction] WHERE SiloId IN (1,2,3) AND Time >…
Ilya Chernomordik
  • 27,817
  • 27
  • 121
  • 207
0
votes
0 answers

Error SQL71501: Error validating element on a stored procedure

We have a stored procedure which calls a table valued function like this DECLARE @PID INT DECLARE @PCost DECIMAL(30,15) SELECT @ID = PID, @PCost = Cost FROM [dbo].[myfunction] (@param1, @param2) but when we try to generate a .dacpac from SSMS, we…
0
votes
0 answers

Bulk update using TVP works in SSMS but not C#

Using VS2019 and SQL Server 2019 i cannot get a stored procedure to update all expected rows when called from C#, it updates 1 row only, the lowest value. I am using a TVP to pass in multiple rows, I want to use a value from this to update…
0
votes
1 answer

TVP not being supplied in stored procedure call from Powershell

Can't figure out where I'm going wrong here, the TVP in the stored procedure references @asn but I keep getting the below error/warning, I've tried everything, there is no further details in the sql server logs, any help appreciated. PowerShell…
0
votes
0 answers

Cross Applied Table Value Function with Two Parameters

I'm trying to create a function that returns the status of an Enquiry on a specified date. When I create this function with date as the only parameter it works, but modifying the function to also filter by Enquiry Key returns no rows. Please let me…
corky
  • 15
  • 6
0
votes
3 answers

How do I iterate through subsets of a table in SQL

I'm new to SQL and I would appreciate any advice! I have a table that stores the history of an order. It includes the following columns: ORDERID, ORDERMILESTONE, NOTES, TIMESTAMP. There is one TIMESTAMP for every ORDERMILESTONE in an ORDERID and…
0
votes
0 answers

SQL Stored Procedure - Compare C# Dictionary to JSON

I have a C# dictionary object I would like to pass to an SQL stored procedure and compare its contents to a field containing JSON string. Dictionary d = new Dictionary d.Add("A",True); d.Add("B",False); Let's presume…
leighhydes
  • 77
  • 1
  • 2
  • 8