 |
|
 |
|
Next: How to get user define defalue_value ?
|
| Author |
Message |
External

Since: Jan 12, 2008 Posts: 11
|
(Msg. 1) Posted: Thu Jan 31, 2008 2:33 am
Post subject: Insert multiple rows with stored procedures Archived from groups: microsoft>public>sqlserver>programming (more info?)
|
|
|
|
|
| Back to top |
|
 |  |
External

Since: Jan 11, 2008 Posts: 46
|
(Msg. 2) Posted: Thu Jan 31, 2008 10:43 am
Post subject: Re: Insert multiple rows with stored procedures [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
Two potential options:
1)Pass in as an array , but then you will need to split the array and run
the relevant INSERT multiple times within the stored procedure
2)Run the stored procedure(s) multiple times from within your application
Normally , I prefer option 2) , but this depends on the application
--
Jack Vamvas
___________________________________
Search IT jobs from multiple sources- http://www.ITjobfeed.com
"Ricardo Luceac" wrote in message
>
> Hi all...
>
> How can I pass multiple rows parameters for a stored procedure??
>
> For example:
>
> I have an order table and a orderitens table.
>
> I need to insert the order, and insert the orderitems with the
> id of teh order... But te orderitems will have more than 1...
>
>
> thx...
>
> *** Sent via Developersdex http://www.developersdex.com *** >> Stay informed about: Insert multiple rows with stored procedures |
|
| Back to top |
|
 |  |
External

Since: Jan 29, 2004 Posts: 1559
|
(Msg. 3) Posted: Thu Jan 31, 2008 11:41 am
Post subject: Re: Insert multiple rows with stored procedures [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
|
|
| Back to top |
|
 |  |
External

Since: Jan 10, 2008 Posts: 20
|
(Msg. 4) Posted: Thu Jan 31, 2008 12:17 pm
Post subject: Re: Insert multiple rows with stored procedures [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
Hi Ricardo,
Nowadays using XML is the best option (better than comma separated values
unless you have strong network bandwidth restrictions) . In SQL Server 2008
you have table valued parameters that will solve your problem in a efficient
and elegant way
--
Rubén Garrigós
Solid Quality Mentors
"Ricardo Luceac" wrote in message
>
> Hi all...
>
> How can I pass multiple rows parameters for a stored procedure??
>
> For example:
>
> I have an order table and a orderitens table.
>
> I need to insert the order, and insert the orderitems with the
> id of teh order... But te orderitems will have more than 1...
>
>
> thx...
>
> *** Sent via Developersdex http://www.developersdex.com *** >> Stay informed about: Insert multiple rows with stored procedures |
|
| Back to top |
|
 |  |
External

Since: Dec 21, 2009 Posts: 1
|
(Msg. 5) Posted: Mon Dec 21, 2009 1:01 am
Post subject: Insert multiple rows with stored procedures [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
Hi Friend,
You can use the follwowing format of SP to insert multiple rows of data in a single SP.
You can pass values as comma seperated values.
For the following SP
Input can be:
MemberId =10
MemberProductId =12,14,35,67,89
CREATE PROCEDURE dbo.insertMemberProductFavorite
(
@MemberId int,
@MemberProductId varchar(100)
)
AS
DECLARE @count int
DECLARE @str VARCHAR(8000)
DECLARE @spot SMALLINT
WHILE @MemberProductId <> ''
BEGIN
SET @spot = CHARINDEX(',', @MemberProductId)
IF @spot>0
BEGIN
SET @str = CAST(LEFT(@MemberProductId, @spot-1) AS INT)
SET @MemberProductId = RIGHT(@MemberProductId, LEN(@MemberProductId)-@spot)
END
ELSE
BEGIN
SET @str = CAST(@MemberProductId AS INT)
SET @MemberProductId = ''
END
SELECT @count=count(1) FROM MemberProductFavorite
WHERE MemberProductId=@str
AND MemberId=@MemberId
IF @count =0
BEGIN
INSERT INTO MemberProductFavorite
(MemberId,
MemberProductId)
VALUES
( @MemberId,
@str)
END
END
RETURN
GO
Enjoy Coding
Thanks & Regards,
Fouzan.Y.
Ricardo Luceac wrote:
Insert multiple rows with stored procedures
31-Jan-08
Hi all...
How can I pass multiple rows parameters for a stored procedure??
For example:
I have an order table and a orderitens table.
I need to insert the order, and insert the orderitems with the
id of teh order... But te orderitems will have more than 1...
thx...
*** Sent via Developersdex http://www.developersdex.com ***
Previous Posts In This Thread:
On Thursday, January 31, 2008 5:33 AM
Ricardo Luceac wrote:
Insert multiple rows with stored procedures
Hi all...
How can I pass multiple rows parameters for a stored procedure??
For example:
I have an order table and a orderitens table.
I need to insert the order, and insert the orderitems with the
id of teh order... But te orderitems will have more than 1...
thx...
*** Sent via Developersdex http://www.developersdex.com ***
On Thursday, January 31, 2008 5:41 AM
Tibor Karaszi wrote:
Consider passing the order as XML and use OPENXML (if 2000) or .
Consider passing the order as XML and use OPENXML (if 2000) or .Nodes (if 2005). You will find more
info in general on this topic at www.sommarskog.se.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://sqlblog.com/blogs/tibor_karaszi
"Ricardo Luceac" wrote in message
On Thursday, January 31, 2008 5:43 AM
Jack Vamvas wrote:
Re: Insert multiple rows with stored procedures
Two potential options:
1)Pass in as an array , but then you will need to split the array and run
the relevant INSERT multiple times within the stored procedure
2)Run the stored procedure(s) multiple times from within your application
Normally , I prefer option 2) , but this depends on the application
--
Jack Vamvas
___________________________________
Search IT jobs from multiple sources- http://www.ITjobfeed.com
"Ricardo Luceac" wrote in message
On Thursday, January 31, 2008 6:17 AM
novalidaddres wrote:
Hi Ricardo,Nowadays using XML is the best option (better than comma separated
Hi Ricardo,
Nowadays using XML is the best option (better than comma separated values
unless you have strong network bandwidth restrictions) . In SQL Server 2008
you have table valued parameters that will solve your problem in a efficient
and elegant way :)
--
Rub?n Garrig?s
Solid Quality Mentors
"Ricardo Luceac" wrote in message
Submitted via EggHeadCafe - Software Developer Portal of Choice
ASP.NET Process Killer Revisited
http://www.eggheadcafe.com/tutorials/aspnet/761a922d-7b70-4df6-9e23-4a...d7bc912 >> Stay informed about: Insert multiple rows with stored procedures |
|
| Back to top |
|
 |  |
External

Since: Aug 24, 2003 Posts: 1744
|
(Msg. 6) Posted: Mon Dec 21, 2009 5:25 am
Post subject: Re: Insert multiple rows with stored procedures [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
Hi
There are so many techniques on the internet
DECLARE @MemberId INT,@MemberProductId VARCHAR(20)
SET @MemberId =10
SET @MemberProductId ='12,14,35,67,89'
INSERT INTO....
SELECT @MemberId,Item FROM
ListString(@MemberProductId)
/*
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER function [dbo].[ListString] (@List varchar(8000))
returns table
as return (
select substring(List, [Number] + 1,
charindex(',', List, [Number] + 1) - ([Number] +1 )) Item
from (select ',' + @List + ',' List) OL
join numbers on substring(List, [Number], 4000) like ',_%'
and [Number] betwe
*/
<Fouzan Yoosuf> wrote in message ...
> Hi Friend,
>
> You can use the follwowing format of SP to insert multiple rows of data in
> a single SP.
>
> You can pass values as comma seperated values.
>
> For the following SP
> Input can be:
>
> MemberId =10
>
> MemberProductId =12,14,35,67,89
>
>
> CREATE PROCEDURE dbo.insertMemberProductFavorite
> (
> @MemberId int,
> @MemberProductId varchar(100)
>
> )
> AS
> DECLARE @count int
> DECLARE @str VARCHAR(8000)
> DECLARE @spot SMALLINT
> WHILE @MemberProductId <> ''
> BEGIN
> SET @spot = CHARINDEX(',', @MemberProductId)
> IF @spot>0
> BEGIN
> SET @str = CAST(LEFT(@MemberProductId, @spot-1) AS INT)
> SET @MemberProductId = RIGHT(@MemberProductId,
> LEN(@MemberProductId)-@spot)
> END
> ELSE
> BEGIN
> SET @str = CAST(@MemberProductId AS INT)
> SET @MemberProductId = ''
> END
> SELECT @count=count(1) FROM MemberProductFavorite
> WHERE MemberProductId=@str
> AND MemberId=@MemberId
> IF @count =0
> BEGIN
> INSERT INTO MemberProductFavorite
> (MemberId,
> MemberProductId)
> VALUES
> ( @MemberId,
> @str)
> END
> END
> RETURN
> GO
>
> Enjoy Coding
>
> Thanks & Regards,
>
> Fouzan.Y.
>
>
>
> Ricardo Luceac wrote:
>
> Insert multiple rows with stored procedures
> 31-Jan-08
>
> Hi all...
>
> How can I pass multiple rows parameters for a stored procedure??
>
> For example:
>
> I have an order table and a orderitens table.
>
> I need to insert the order, and insert the orderitems with the
> id of teh order... But te orderitems will have more than 1...
>
>
> thx...
>
> *** Sent via Developersdex http://www.developersdex.com ***
>
> Previous Posts In This Thread:
>
> On Thursday, January 31, 2008 5:33 AM
> Ricardo Luceac wrote:
>
> Insert multiple rows with stored procedures
> Hi all...
>
> How can I pass multiple rows parameters for a stored procedure??
>
> For example:
>
> I have an order table and a orderitens table.
>
> I need to insert the order, and insert the orderitems with the
> id of teh order... But te orderitems will have more than 1...
>
>
> thx...
>
> *** Sent via Developersdex http://www.developersdex.com ***
>
> On Thursday, January 31, 2008 5:41 AM
> Tibor Karaszi wrote:
>
> Consider passing the order as XML and use OPENXML (if 2000) or .
> Consider passing the order as XML and use OPENXML (if 2000) or .Nodes (if
> 2005). You will find more
> info in general on this topic at www.sommarskog.se.
>
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://sqlblog.com/blogs/tibor_karaszi
>
>
> "Ricardo Luceac" wrote in message
>
>
> On Thursday, January 31, 2008 5:43 AM
> Jack Vamvas wrote:
>
> Re: Insert multiple rows with stored procedures
> Two potential options:
> 1)Pass in as an array , but then you will need to split the array and run
> the relevant INSERT multiple times within the stored procedure
> 2)Run the stored procedure(s) multiple times from within your application
>
> Normally , I prefer option 2) , but this depends on the application
>
> --
>
> Jack Vamvas
> ___________________________________
> Search IT jobs from multiple sources- http://www.ITjobfeed.com
>
>
>
>
> "Ricardo Luceac" wrote in message
>
>
> On Thursday, January 31, 2008 6:17 AM
> novalidaddres wrote:
>
> Hi Ricardo,Nowadays using XML is the best option (better than comma
> separated
> Hi Ricardo,
>
> Nowadays using XML is the best option (better than comma separated values
> unless you have strong network bandwidth restrictions) . In SQL Server
> 2008
> you have table valued parameters that will solve your problem in a
> efficient
> and elegant way
>
> --
>
> Rub?n Garrig?s
> Solid Quality Mentors
>
> "Ricardo Luceac" wrote in message
>
>
>
> Submitted via EggHeadCafe - Software Developer Portal of Choice
> ASP.NET Process Killer Revisited
> http://www.eggheadcafe.com/tutorials/aspnet/761a922d-7b70-4df6-9e23-4a...d7bc912 >> Stay informed about: Insert multiple rows with stored procedures |
|
| Back to top |
|
 |  |
External

Since: Jan 10, 2008 Posts: 210
|
(Msg. 7) Posted: Mon Dec 21, 2009 9:45 am
Post subject: Re: Insert multiple rows with stored procedures [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
In Sql Server 2005, my preferred method is passing in the data via xml, and
shredding the xml.
Most times I shred the xml into @variable or #temp tables. Then I interact
with the @variable or #temp table when I need to insert data into the real
tables.
See:
http://pratchev.blogspot.com/2007/06/shredding-xml-in-sql-server-2005.html
In 2008,
http://www.google.com/#hl=en&safe=active&q=sql+server+2008+table+value...rameter
.........
<Fouzan Yoosuf> wrote in message ...
> Hi Friend,
>
> You can use the follwowing format of SP to insert multiple rows of data in
> a single SP.
>
> You can pass values as comma seperated values.
>
> For the following SP
> Input can be:
>
> MemberId =10
>
> MemberProductId =12,14,35,67,89
>
>
> CREATE PROCEDURE dbo.insertMemberProductFavorite
> (
> @MemberId int,
> @MemberProductId varchar(100)
>
> )
> AS
> DECLARE @count int
> DECLARE @str VARCHAR(8000)
> DECLARE @spot SMALLINT
> WHILE @MemberProductId <> ''
> BEGIN
> SET @spot = CHARINDEX(',', @MemberProductId)
> IF @spot>0
> BEGIN
> SET @str = CAST(LEFT(@MemberProductId, @spot-1) AS INT)
> SET @MemberProductId = RIGHT(@MemberProductId,
> LEN(@MemberProductId)-@spot)
> END
> ELSE
> BEGIN
> SET @str = CAST(@MemberProductId AS INT)
> SET @MemberProductId = ''
> END
> SELECT @count=count(1) FROM MemberProductFavorite
> WHERE MemberProductId=@str
> AND MemberId=@MemberId
> IF @count =0
> BEGIN
> INSERT INTO MemberProductFavorite
> (MemberId,
> MemberProductId)
> VALUES
> ( @MemberId,
> @str)
> END
> END
> RETURN
> GO
>
> Enjoy Coding
>
> Thanks & Regards,
>
> Fouzan.Y.
>
>
>
> Ricardo Luceac wrote:
>
> Insert multiple rows with stored procedures
> 31-Jan-08
>
> Hi all...
>
> How can I pass multiple rows parameters for a stored procedure??
>
> For example:
>
> I have an order table and a orderitens table.
>
> I need to insert the order, and insert the orderitems with the
> id of teh order... But te orderitems will have more than 1...
>
>
> thx...
>
> *** Sent via Developersdex http://www.developersdex.com ***
>
> Previous Posts In This Thread:
>
> On Thursday, January 31, 2008 5:33 AM
> Ricardo Luceac wrote:
>
> Insert multiple rows with stored procedures
> Hi all...
>
> How can I pass multiple rows parameters for a stored procedure??
>
> For example:
>
> I have an order table and a orderitens table.
>
> I need to insert the order, and insert the orderitems with the
> id of teh order... But te orderitems will have more than 1...
>
>
> thx...
>
> *** Sent via Developersdex http://www.developersdex.com ***
>
> On Thursday, January 31, 2008 5:41 AM
> Tibor Karaszi wrote:
>
> Consider passing the order as XML and use OPENXML (if 2000) or .
> Consider passing the order as XML and use OPENXML (if 2000) or .Nodes (if
> 2005). You will find more
> info in general on this topic at www.sommarskog.se.
>
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://sqlblog.com/blogs/tibor_karaszi
>
>
> "Ricardo Luceac" wrote in message
>
>
> On Thursday, January 31, 2008 5:43 AM
> Jack Vamvas wrote:
>
> Re: Insert multiple rows with stored procedures
> Two potential options:
> 1)Pass in as an array , but then you will need to split the array and run
> the relevant INSERT multiple times within the stored procedure
> 2)Run the stored procedure(s) multiple times from within your application
>
> Normally , I prefer option 2) , but this depends on the application
>
> --
>
> Jack Vamvas
> ___________________________________
> Search IT jobs from multiple sources- http://www.ITjobfeed.com
>
>
>
>
> "Ricardo Luceac" wrote in message
>
>
> On Thursday, January 31, 2008 6:17 AM
> novalidaddres wrote:
>
> Hi Ricardo,Nowadays using XML is the best option (better than comma
> separated
> Hi Ricardo,
>
> Nowadays using XML is the best option (better than comma separated values
> unless you have strong network bandwidth restrictions) . In SQL Server
> 2008
> you have table valued parameters that will solve your problem in a
> efficient
> and elegant way
>
> --
>
> Rub?n Garrig?s
> Solid Quality Mentors
>
> "Ricardo Luceac" wrote in message
>
>
>
> Submitted via EggHeadCafe - Software Developer Portal of Choice
> ASP.NET Process Killer Revisited
> http://www.eggheadcafe.com/tutorials/aspnet/761a922d-7b70-4df6-9e23-4a...d7bc912 >> Stay informed about: Insert multiple rows with stored procedures |
|
| Back to top |
|
 |  |
External

Since: Dec 22, 2009 Posts: 1
|
(Msg. 8) Posted: Tue Dec 22, 2009 11:47 am
Post subject: Re: Insert multiple rows with stored procedures [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
use SQL 2008 and lookup TVPs.
http://msdn.microsoft.com/en-us/library/bb522663.aspx
you can do something like this.
exec my_invoice_procedure NAME, DATE, INVOICE_NUMBER, TVPitems
TVPitems is a table that has rows of data where each row represents another
line item of the invoice.
Leon
<Fouzan Yoosuf> wrote in message ...
> Hi Friend,
>
> You can use the follwowing format of SP to insert multiple rows of data in
> a single SP.
>
> You can pass values as comma seperated values.
>
> For the following SP
> Input can be:
>
> MemberId =10
>
> MemberProductId =12,14,35,67,89
>
>
> CREATE PROCEDURE dbo.insertMemberProductFavorite
> (
> @MemberId int,
> @MemberProductId varchar(100)
>
> )
> AS
> DECLARE @count int
> DECLARE @str VARCHAR(8000)
> DECLARE @spot SMALLINT
> WHILE @MemberProductId <> ''
> BEGIN
> SET @spot = CHARINDEX(',', @MemberProductId)
> IF @spot>0
> BEGIN
> SET @str = CAST(LEFT(@MemberProductId, @spot-1) AS INT)
> SET @MemberProductId = RIGHT(@MemberProductId,
> LEN(@MemberProductId)-@spot)
> END
> ELSE
> BEGIN
> SET @str = CAST(@MemberProductId AS INT)
> SET @MemberProductId = ''
> END
> SELECT @count=count(1) FROM MemberProductFavorite
> WHERE MemberProductId=@str
> AND MemberId=@MemberId
> IF @count =0
> BEGIN
> INSERT INTO MemberProductFavorite
> (MemberId,
> MemberProductId)
> VALUES
> ( @MemberId,
> @str)
> END
> END
> RETURN
> GO
>
> Enjoy Coding
>
> Thanks & Regards,
>
> Fouzan.Y.
>
>
>
> Ricardo Luceac wrote:
>
> Insert multiple rows with stored procedures
> 31-Jan-08
>
> Hi all...
>
> How can I pass multiple rows parameters for a stored procedure??
>
> For example:
>
> I have an order table and a orderitens table.
>
> I need to insert the order, and insert the orderitems with the
> id of teh order... But te orderitems will have more than 1...
>
>
> thx...
>
> *** Sent via Developersdex http://www.developersdex.com ***
>
> Previous Posts In This Thread:
>
> On Thursday, January 31, 2008 5:33 AM
> Ricardo Luceac wrote:
>
> Insert multiple rows with stored procedures
> Hi all...
>
> How can I pass multiple rows parameters for a stored procedure??
>
> For example:
>
> I have an order table and a orderitens table.
>
> I need to insert the order, and insert the orderitems with the
> id of teh order... But te orderitems will have more than 1...
>
>
> thx...
>
> *** Sent via Developersdex http://www.developersdex.com ***
>
> On Thursday, January 31, 2008 5:41 AM
> Tibor Karaszi wrote:
>
> Consider passing the order as XML and use OPENXML (if 2000) or .
> Consider passing the order as XML and use OPENXML (if 2000) or .Nodes (if
> 2005). You will find more
> info in general on this topic at www.sommarskog.se.
>
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://sqlblog.com/blogs/tibor_karaszi
>
>
> "Ricardo Luceac" wrote in message
>
>
> On Thursday, January 31, 2008 5:43 AM
> Jack Vamvas wrote:
>
> Re: Insert multiple rows with stored procedures
> Two potential options:
> 1)Pass in as an array , but then you will need to split the array and run
> the relevant INSERT multiple times within the stored procedure
> 2)Run the stored procedure(s) multiple times from within your application
>
> Normally , I prefer option 2) , but this depends on the application
>
> --
>
> Jack Vamvas
> ___________________________________
> Search IT jobs from multiple sources- http://www.ITjobfeed.com
>
>
>
>
> "Ricardo Luceac" wrote in message
>
>
> On Thursday, January 31, 2008 6:17 AM
> novalidaddres wrote:
>
> Hi Ricardo,Nowadays using XML is the best option (better than comma
> separated
> Hi Ricardo,
>
> Nowadays using XML is the best option (better than comma separated values
> unless you have strong network bandwidth restrictions) . In SQL Server
> 2008
> you have table valued parameters that will solve your problem in a
> efficient
> and elegant way
>
> --
>
> Rub?n Garrig?s
> Solid Quality Mentors
>
> "Ricardo Luceac" wrote in message
>
>
>
> Submitted via EggHeadCafe - Software Developer Portal of Choice
> ASP.NET Process Killer Revisited
> http://www.eggheadcafe.com/tutorials/aspnet/761a922d-7b70-4df6-9e23-4a...d7bc912 >> Stay informed about: Insert multiple rows with stored procedures |
|
| Back to top |
|
 |  |
| Related Topics: | Multiple Rows INSERT - Hi, I have a tbl1 with four columns. RecId, Branch, branchName, Notes I another tabl, tbl2 with three cols: CompId, Comp, cFlag, notes Thrid table tbl3 CompId, Comp, aFlag, Branch, Notes I am trying to write an INSERT trigger on tbl2 which will..
Passing form parameter to multiple SQL stored procedures - Dear community: I have two append (SPappend1 and SPappend2) and two update (SPupdate1 and SPupdate2) stored procedures that execute at the click of a button on my main Access .adp form (frmUSERID). Each stored procedure has @Enter_UserID in the criteri...
INSTEAD trigger, primary key, multiple rows, INSERT/UPDATE.. - 1. Primary keys must be unique. 2. One of the touted purposes of INSTEAD triggers is to let the classic "insert if new, update if exists" decision be done in the trigger, so that the calling logic can just do INSERT and not worry about it. For...
Converting Multiple Rows Into Single CSV Rows - Hi, Hoping someone could help me convert this data... ID Size 60203 M 60203 L 60203 XXL 30020 10 30020 8 ....into this... ID Size 60203 M,L,XXL 30020 10,8 Any help would be greatly appreciated. Thx, EightBall
stored procedures - Is it possible, if so, how do you exec a SP and have the results from it be usable so it could be joined into another table? Even if I have to store the results into a temp table first is fine..... |
|
You can post new topics in this forum You can reply to topics in this forum You can edit your posts in this forum You can delete your posts in this forum You can vote in polls in this forum
|
|
|
|
 |
|
|