.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

using table valued parameters for stored procedures any limitations

Posted By:      Posted Date: September 20, 2010    Points: 0   Category :Sql Server
I am thinking of using a table valued parameter for my new stored procedure, but wonder if there are any performance implications to be aware of and is the limitation of using statistics applicable with table value parameters, i.e do they keep statistics and will this affect the judgement of query plans i.e estimated number of rows, from my experience table variables do suffer from this problem but I would like to confirm if it applies to table value parameters as well.

View Complete Post

More Related Resource Links

Which jdbc version support table valued parameters to stored procedures?


Hi all,

I want to use table valued parameters in stored procedures; we have that in .NET client, so I do not want to write another version for jdbc client.

Does anyone know, which version of jdbc engine support that function?

Please give several lines of source codes.

Thanks a million,



Replication stored procedures not being passed parameters- default appears instead

Hi I am setting up transactional replication from Oracle to SQL Server, it is working fine for 9 tables, but for one it fails on updating and deleting with a message like this: Procedure or function 'spu_VGSM_SUBMISSION_CONTACT' expects parameter '@pkc1', which was not supplied. This is correct, in that the sp should be being passed this parameter, but when I do a trace it will show something like: exec "spd_VGSM_SUBMISSION_CONTACT" '12-3456-10','BLOGGS','S', '2010-07-01 12:43:43', 'M123456' default In other words, the old primary key values which should be being passed in are being replaced with "default". I am using the CALL syntax for the update sp. If anyone can suggest why this is I would be very grateful. This is the publication: exec sp_addpublication @publication = N'_Submission_Contact', @description = N'Transactional publication from Oracle Publisher.', @sync_method = N'concurrent_c', @retention = 0, @allow_push = N'true', @allow_pull = N'true', @allow_anonymous = N'false', @enabled_for_internet = N'false', @snapshot_in_defaultfolder = N'true', @compress_snapshot = N'false', @ftp_port = 21, @ftp_login = N'anonymous', @allow_subscription_copy = N'false', @add_to_active_directory = N'false', @repl_freq = N'continuous', @status = N'active', @independent_agent = N'true', @immediate_sync = N'

Entity Framework and stored procedures with OUTPUT parameters (suggest API)

EF does handle stored procedures with OUTPUT parameters, but the generated methods are not the easiest to work with or safest you could ask for. The ObjectParameter objects you have to create, pass to the method and extract the value from are not type checked and reallyObjectParameter nameParam = new ObjectParameter( "Name", typeof(string)); ObjectParameter ageParam = new ObjectParameter( "Age", typeof(int)); context.GetPersonsNameAndAge( personId, nameParam, ageParam); string name = Convert.IsDBNull(nameParam.Value) ? null : (string)nameParam.Value; int? age = Convert.IsDBNull(ageParam.Value) ? null : (int?)ageParam.Value; is not what I would want to have to write.The ObjectParameter objects do make some sense for stored procedures that return both a resultset and some OUTPUT parameters, because in that case the OUTPUT parameters are only available after the resultset has been consumed and therefore you need some objects that will be populated after the ObjectResult<...> gets processed but for the stored procedures that do not return any resultset, there is no reason not to create the ObjectParameter objects within the method and extract the values there as well. So that the procedure above may be called asstring name; int? age; context.GetPersonsNameAndAge( personId, out name, out age); Things are not so simple for procedures returning both. I'm

Cannot call Table Valued Function from Dynamic stored procedure statement

Hello,  I have a table-valued function that splits string into a table column. I can easily call this function from a stored procedure within a regular SELECT statement: SELECT * FROM Table1 WHERE Code1 = '1' AND Code2 IN(SELECT * FROM [dbo].[fnSplitValues](@Code2String))   However when I try to use the same logic for a dynamic SELECT statement: ‘SELECT * FROM Table1 WHERE Code1 = '1' AND Code2 IN(SELECT * FROM ' + [dbo].[fnSplitValues](@Code2String) + ')’ I get an error ‘Cannot find either column "dbo" or the user-defined function or aggregate "dbo.fnSplitValues", or the name is ambiguous.’ Any idea what is wrong with my dynamic SQL?   Please help, Lana

Table Valued Parameters (TVP)


hi all;

this is new to me but i want to have a TVP to accept list of records as a parameter of a stored procedure. the following is the code i have written.

CREATE TABLE dbo.GroupRole
userRole VARCHAR(100) NOT NULL,


CREATE PROCEDURE grpRoleRecorder (@userRole usrRoleArr READONLY)
 INSERT INTO dbo.GroupRole VALUES (@userRole);

when i execute the code it gives the folling error.

Msg 137, Level 16, State 1, Procedure grpRoleRecorder, Line 4
Must declare the scalar variable "@userRole".

Please help me on this.

Thank You All

using a checkbox list and Table Valued Parameters


I have a checkboxlist that gets all all the items from a look up table. The user is going to go to the list, check certail items and insert the checkboxid, the value (0 or 1),  and the userid  into a table valued paramater using a stored procedure. I have the user defined table type created but thats about it. Any body out there have any hints.

Using ADO.NET SqlDbType.Structured TVP (Table Valued Parameters) causes SQL Compilation for every ca


When calling a stored procedure with a table valued parameter from ADO.Net, each call requires a SQL Compilation.  In an application that makes this call thousands of times per second, this causes SQL Compilations thousands of times per second leading to degraded performance.

When calling the same stored procedure directly from Management Studio, no SQL Compilations are performed.

Steps to reproduce ...

1. Create the following User Defined Type and Stored Procedure (SQL2008 required) ...

CREATE TYPE [dbo].[BigIntListType] AS TABLE(
 [Id] [bigint] NOT NULL,
  [Id] ASC

  @itemIds AS BigIntListType READONLY
  SELECT col1, col2 FROM table1
  JOIN @itemIds ON table1.id = @itemIds.Id

2. Start SQL Profiler and capture "Showplan XML for Query Compile".  Start Perfmon and add "SQL Compilations / Second"

3. Run the following code from Management Studio as many times as possible ...

declare @p2 dbo.BigIntListType

insert into @p2 values(601)
insert into @p2 values(1)

exec testProc @itemIds = @p2

How to call a Stored procedures with varchar output parameters in LINQ


I have a stored procedure with the following structure:

CREATE procedure EditFeriodigiesForm
@EditID int,
@producer varchar(50) output,
@IssuedDate datetime output,
@stadio varchar(50) output,
@Method varchar(50) output,
@Monades_N varchar(50) output,
@Monades_P varchar(50) output,
@Monades_K varchar(50) output,
@comments varchar(100) output,
@responsible varchar(50) output
Begin Try
	Begin tran
SELECT @IssuedDate=IssuedDate,@producer=ProducerID,@stadio=KalliergitikoStadio,@Method=Method,@Monades_N=Monades_N,@Monades_P=Monades_P,@Monades_K=Monades_K,@comments=Comments,@responsible=Responsible from ferti_odigies WHERE FertOdigiesID=@EditID
end try
	Begin catch
	if @@error>0
declare @ErrMsg varchar(4000),
		@ErrSeverity int
Select @ErrMsg=Error_Message(),

Raiserror(@ErrMsg ,@ErrSeverity,1)

end catch 

Now i need to call it in LINQ.I have done the mapping thing and the SPROC is ready to be called in my form.aspx.cs form, as following:
  int id = Edit_id;
            int? producer;
            DateTime date =Convert.ToDateTime(txtdate.Text);
            string stadio;
            string method="";
            string monadesn="";
            string monadesp="";
            string mo

Input and output parameters for stored procedures in VB.NET


I have several VB.NET functions which pass and receive values from executed stored procedures using parameters. However, the latest method I am using seems to be a little too specific on the datatype and data length of the parameters for my liking (i.e. LogActivityCommand.Parameters.Add("@strErrSource", SqlDbType.NVarChar, 300).Value = strErrSource). For example:

Public Function LogError(ByVal strErrSource As String, ByVal strErrCode As String, ByVal strErrDesc As String) As String  
    Dim AerialConnection = New SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("aerialConnectionString").ConnectionString)  
    Dim RetVal As SqlParameter  
        Dim LogActivityCommand = New SqlCommand("spLogError", AerialConnection)  
        LogActivityCommand.CommandType = CommandType.StoredProcedure  
        'Add input parameters  
        LogActivityCommand.Parameters.Add("@strErrSource", SqlDbType.NVarChar, 300).Value = strErrSource &

Pass parameters into multi stored procedures



I have a code that want to call 2 stored procedures with a sqlcommand; I'm used :


        string sqlcmds = "EXEC ShowDetailsSp;EXEC ShowBannersSp;";
        cmd = new SqlCommand(sqlcmds, sqlcon);
        cmd.Parameters.AddWithValue("@Number", number);
        cmd.Parameters.AddWithValue("@Code", Code);

each stord procedure has a parameter :

@Number is for ShowDetailsSp and @Code is for ShowBannersSp, but when I run my page give error :

Procedure or function 'ShowDetailsSp' expects parameter '@Number', which was not supplied. 

Pass parameters into multi stored procedures



I have a code that want to call 2 stored procedures with a sqlcommand; I'm used :


        string sqlcmds = "EXEC ShowDetailsSp;EXEC ShowBannersSp;";
        cmd = new SqlCommand(sqlcmds, sqlcon);
        cmd.Parameters.AddWithValue("@Number", number);
        cmd.Parameters.AddWithValue("@Code", Code);

each stord procedure has a parameter :

@Number is for ShowDetailsSp and @Code is for ShowBannersSp, but when I run my page give error :

Procedure or function 'ShowDetailsSp' expects parameter '@Number', which was not supplied. 

Transact-SQL Built-In Stored Procedures

To assist you with managing Microsoft SQL Server databases, Transact-SQL provides many built-in stored procedures.

Renaming an Object

Sending Email

FormView -- Parameters and asp:Table


I've already solved this problem to my satisfaction, I just want to know WHY it works this way.

I have a FormView control bound to an ObjectDataSource.  Let's say our data source is a hypothetical table with three columns:  id, name, age.  Why is it that when I use the <asp:Table> element inside of the FormView, the parameter values are not set, but when I use the standard <table> tag, it works fine?

This seems like a .NET problem to me.  I expect the <asp:Table> element to work in the same way as <table> because they are, for all intents and purposes, the same thing.  Am I missing something?

SqlDataSource how to change the stored procedures at run time



Is it possible to change the select, insert and update stored procedure of an SqlDataSource at run time. I don't mean to change the definition of the stored procedure, but I mean to change the assignment, i.e. To change the select stored procedure from "selectSP1" to "selectSP2" at run time. Is it possible?



Test Run: Testing SQL Stored Procedures Using LINQ


Language Integrated Query makes lots of things easier. Here we put LINQ, or more specifically the LINQ to SQL provider, to use testing SQL stored procedures.

Dr. James McCaffrey

MSDN Magazine April 2008

Advanced T-SQL: Automate the Generation of Stored Procedures for Your Database


Design-time automation makes coding faster and ensures that all the procedures generated use the same naming conventions and structure. In an effort to improve their coding efficiency in a large SQL project, the authors wrote a set of design-time stored procedures that generate run-time stored procedures, and have used them in project after project ever since. Recently, the authors updated their procedures to make use of SQL Server 2000 features, including user-defined functions. This article covers the creation and execution of these dynamic T-SQL scripts to automate the coding of common database stored procedures.

Peter W. DeBetta and J. Byer Hill

MSDN Magazine April 2003

.NET Reflection: Dynamically Bind Your Data Layer to Stored Procedures and SQL Commands Using .NET M


One major inconvenience of using SQL stored procedures from code is having to match type information. You have to write long wrapper functions around the procedures just to expose the data types. In the .NET Framework, however, the reflection services of the System.Reflection namespace allow you to query rich metadata that describe data types. This article explains how to use reflection in .NET to end your stored procedure nightmares. The author creates four custom classes, including one that generates a SQLCommand object based on the metadata of a method. Using this library, you'll be on your way to automating the generation of stored procedures.

Atif Aziz

MSDN Magazine August 2002

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend