table-valued-parameters

How to improve the code of stored procedure with inner join to possible empty tvp

旧城冷巷雨未停 提交于 2019-12-20 04:56:21
问题 I want to improve the code of the following stored procedure. I want to join it into single select statement. Can you purpose a better way? CREATE PROCEDURE [dbo].[pr_FinDocument_Filter] @finDocIdForFilter [dbo].[GuidList] READONLY, @filteredSid nvarchar(64), @filteringOffsetInDay int AS BEGIN IF (@filteredSid is null or @filteringOffsetInDay is null) BEGIN RAISERROR(N'arguments must have a value', 15, 1); END IF EXISTS (SELECT 1 FROM @finDocIdForFilter) BEGIN SELECT fin_doc_extra.docId FROM

Create and Pass a Table-Valued Parameter in a Single Line

风格不统一 提交于 2019-12-19 19:46:28
问题 Using SQL Server 2012, is it possible to eliminate the need to declare a table-valued parameter (TVP) just to pass it into a stored procedure? Below is a really simple example of a stored procedure (SP) that takes a TVP and a working example to execute that SP where I have to declare the TVP, populate it and then pass it into the SP. I would like to be able to simply pass in the population criteria directly to the EXEC call. Is this possible? Scenario Setup: -- Create a sample Users table

Auto Increment SQL Value

强颜欢笑 提交于 2019-12-19 12:22:44
问题 In the infinte wisdom of the global DBA at a firm I am working at right now he has created a table that takes an int as an ID field, but does not auto increment the number. I am passing up a table valued parameter from .Net because it has roughly 100 or more rows of data that are being passed up at any one time and I dont want to kill the application, hammer the network or the SQL Server. So this is my stored procedure CREATE PROCEDURE sp_Insert_Supporting_Error_Info (@tvp [dbo].udt_CEQZW

Handle multiple db updates from c# in SQL Server 2008

点点圈 提交于 2019-12-13 13:25:19
问题 I like to find a way to handle multiple updates to a sql db (with one singe db roundtrip). I read about table-valued parameters in SQL Server 2008 http://www.codeproject.com/KB/database/TableValueParameters.aspx which seems really useful. But it seems I need to create both a stored procedure and a table type to use it. Is that true? Perhaps due to security? I would like to run a text query simply like this: var sql = "INSERT INTO Note (UserId, note) SELECT * FROM @myDataTable"; var

Empty DataTable Causes Errors When Table-Valued Parameter Has VARBINARY Types

空扰寡人 提交于 2019-12-13 08:48:36
问题 I have a C# web application that serves as a passthrough to SQL Server; requests that detail SQL Server commands come in, we parse the request, generate the necessary .Net types and then use them to execute SqlCommands and such. The upshot of that is that the C# web application needs to be very flexible and really can't make too many assumptions about what a request "should" look like. I recently solved a problem that was causing exceptions to be thrown when a table-valued parameter contained

What is the difference between inserting data using Sql insert statements and SqlBulkCopy?

江枫思渺然 提交于 2019-12-12 10:24:04
问题 I have a problem of inserting huge amount of data to SQL server. Previously I was using Entity framework, but it was damn slow for just 100K root level records ( containing separately two distinct collections, where each one is further operating on 200K records roughly ) = roughly 500K-600K records in memory. Here I applied all optimization ( e.g AutoDetectChangesEnabled = false, and recreated and disposed the context after each batch. ) I rejected the solution, and used BulkInsert that's

sql server 2008 table valued parameters linq2sql

不想你离开。 提交于 2019-12-12 08:55:00
问题 Has anybody experimented with these. Is this supported? 回答1: Table Value parameters aren't supported yet in LINQ to SQL. There's a few posts about this on Microsoft's MSDN forums: DbType.Structured not available SQL Server 2k8.User Defined Table Type. Mapping between DbType 'Structured' and Type 'System.Object' The second link refers to Entity Framework, but the underlying issue is the same. 回答2: I actually had to try this myself. :0 It does not seem to be supported. I get this error when

How to pass DataTable as a parameter to Stored Procedure by not commiting the current session transaction?

≡放荡痞女 提交于 2019-12-11 19:55:12
问题 My code looks like this: public void InsertSampleData(DataTable tempTable) { session.Transaction.Commit(); var connection = session.GetSessionImplementation().Connection; using (var sqlConnection = (SqlConnection)connection) { using (var cmd = sqlConnection.CreateCommand()) { cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "dbo.insertData"; cmd.Parameters.Add("@sItems", SqlDbType.Structured); var sqlParam = cmd.Parameters["@Items"]; sqlParam.Direction = ParameterDirection

Table Value Parameter from c#

邮差的信 提交于 2019-12-11 11:50:57
问题 I have read a number of articles and they all look like the following. When I execute from SSMS everything is fine. When I execute from c#, I get no exceptions. When I check the table, the c# did not insert. CREATE TABLE dbo.Rates (Id BIGINT PRIMARY KEY IDENTITY, LocationName NVARCHAR(50) NOT NULL, CostRate INT NOT NULL); GO /* Create a table type. */ CREATE TYPE dbo.RatesType AS TABLE ( LocationName NVARCHAR(50) , CostRate INT ); GO /* Create a procedure to receive data for the table-valued

Identity column in a table-valued parameter in procedure, how to define DataTable

♀尐吖头ヾ 提交于 2019-12-10 18:33:46
问题 Is it possible to pass a parameter of type "table" with a column of type "[int] IDENTITY(1,1)" to a procedure and execute this stored procedure with a DataTable object passed as the input parameter? I get the following error: "INSERT into an identity column not allowed on table variables. The data for table-valued parameter \"@xxxxx\" doesn't conform to the table type of the parameter." The only related comment I was able to find was "If you supply a value for an identity column in a table