You may have faced a situation where you need to pass a bunch of rows & columns as a parameter to your Stored Procedure. To overcome from that situation you can pass as many rows and columns to your procedure.
Here in my blog, I’m going to explain to you guys a very simple way to perform this.
First of all, you need a Table
CREATE TABLE MyRecords
(
ID INT PRIMARY KEY IDENTITY(1,1),
FirstName VARCHAR(50),
LastName VARCHAR(50),
DOB DATETIME
)
Next, you need to create a UDT (User Defined DataType)
CREATE TYPE MyType AS TABLE
(
FirstName VARCHAR(50),
LastName VARCHAR(50),
DOB DATETIME
)
Now, let’s create a Procedure where we will pass a table as a parameter.
CREATE PROCEDURE SP_InsertRecords
(
@table MyType READONLY

Praveen Raveendran PillaiPosted Jun 2, 2014, 6:28 AM
Thanks f0r Sharing..!!!
Nagaraj SPosted May 28, 2014, 10:55 AM
Great Concept. Thanks for sharing it.
Leon PuthPosted May 27, 2014, 6:43 AM
but the concept is great and it speeds up data update/insert a lot as you do not need to to call a proc 5000 times, you call it once with a table of 5000 records.
Leon PuthPosted May 27, 2014, 6:42 AM
Word of warning here: in order to modify the used defined data type, you will have to drop all its dependent items, i,e the proc you use it in, so make sure you get its design right before you actually add it to sql, else it will cause you some extra hassle.