Unix Technical Forum

SQL 2000: Inserting multiple rows into a single table

This is a discussion on SQL 2000: Inserting multiple rows into a single table within the SQL Server forums, part of the Microsoft SQL Server category; --> To anyone that is able to help.... What I am trying to do is this. I have two tables ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-29-2008, 03:38 AM
JB
 
Posts: n/a
Default SQL 2000: Inserting multiple rows into a single table

To anyone that is able to help....

What I am trying to do is this. I have two tables (Orders, and
OrderDetails), and my question is on the order details. I would like
to set up a stored procedure that essentially inserts in the orders
table the mail order, and then insert multiple orderdetails within the
same transaction. I also need to do this via SQL 2000. Right now i
have "x" amount of variables for all columns in my orders tables, and
all Columns in my Order Details table. I.e. @OColumn1, @OColumn2,
@OColumn3, @ODColumn1, @ODColumn2, etc... I would like to create a
stored procedure to insert into Orders, and have that call another
stored procedure to insert all the Order details associated with that
order. The only way I can think of doing it is for the program to pass
me a string of data per column for order details, and parse the string
via T-SQL. I would like to get away from the String format, and go
with something else. If possible I would like the application to
submit a single value per variable multiple times. If I do it this way
though it will be running the entire SP again, and again. Any
suggestions on the best way to solve this would be greatly
appreciated. If anyone can come up with a better way feel free. My
only requirement is that it be done in SQL.

Thank you
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-29-2008, 03:38 AM
Uri Dimant
 
Posts: n/a
Default Re: SQL 2000: Inserting multiple rows into a single table

JB
I am not sure understand you. Why do you need variables for your columns?
First thought
CREATE PROC spInsert_Order
@OrderID int,
.......
........
AS
BEGIN TRAN
INSERT INTO Orders VALUES (@OrderID,...,...,...)
INSERT INTO Orders_Details VALUES ((@OrderID...........)
COMMIT
Second thought

You can create trigger for INSERT on Orders table. When you perform INSERT
statement the trigger is fired and insert appropriate data into
Orders_Details table


"JB" <JBSchuler@tampabay.rr.com> wrote in message
news:972c667c.0404271523.12c4ae22@posting.google.c om...
> To anyone that is able to help....
>
> What I am trying to do is this. I have two tables (Orders, and
> OrderDetails), and my question is on the order details. I would like
> to set up a stored procedure that essentially inserts in the orders
> table the mail order, and then insert multiple orderdetails within the
> same transaction. I also need to do this via SQL 2000. Right now i
> have "x" amount of variables for all columns in my orders tables, and
> all Columns in my Order Details table. I.e. @OColumn1, @OColumn2,
> @OColumn3, @ODColumn1, @ODColumn2, etc... I would like to create a
> stored procedure to insert into Orders, and have that call another
> stored procedure to insert all the Order details associated with that
> order. The only way I can think of doing it is for the program to pass
> me a string of data per column for order details, and parse the string
> via T-SQL. I would like to get away from the String format, and go
> with something else. If possible I would like the application to
> submit a single value per variable multiple times. If I do it this way
> though it will be running the entire SP again, and again. Any
> suggestions on the best way to solve this would be greatly
> appreciated. If anyone can come up with a better way feel free. My
> only requirement is that it be done in SQL.
>
> Thank you



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-29-2008, 03:39 AM
Erland Sommarskog
 
Posts: n/a
Default Re: SQL 2000: Inserting multiple rows into a single table

JB (JBSchuler@tampabay.rr.com) writes:
> What I am trying to do is this. I have two tables (Orders, and
> OrderDetails), and my question is on the order details. I would like
> to set up a stored procedure that essentially inserts in the orders
> table the mail order, and then insert multiple orderdetails within the
> same transaction. I also need to do this via SQL 2000. Right now i
> have "x" amount of variables for all columns in my orders tables, and
> all Columns in my Order Details table. I.e. @OColumn1, @OColumn2,
> @OColumn3, @ODColumn1, @ODColumn2, etc... I would like to create a
> stored procedure to insert into Orders, and have that call another
> stored procedure to insert all the Order details associated with that
> order. The only way I can think of doing it is for the program to pass
> me a string of data per column for order details, and parse the string
> via T-SQL. I would like to get away from the String format, and go
> with something else.


There is no need for you to compose your string format and parse it.
Pass the string as XML instead, and use sp_xml_preparedocument and
OPENXML to unpack it. Now you can pass many orders and their order details
if you like.




--
Erland Sommarskog, SQL Server MVP, sommar@algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-29-2008, 03:39 AM
Ellen K.
 
Posts: n/a
Default Re: SQL 2000: Inserting multiple rows into a single table

You can easily pass multiple rows into a stored procedure using XML.

But I don't understand what you mean by variables for your columns.

On 27 Apr 2004 16:23:24 -0700, JBSchuler@tampabay.rr.com (JB) wrote:

>To anyone that is able to help....
>
>What I am trying to do is this. I have two tables (Orders, and
>OrderDetails), and my question is on the order details. I would like
>to set up a stored procedure that essentially inserts in the orders
>table the mail order, and then insert multiple orderdetails within the
>same transaction. I also need to do this via SQL 2000. Right now i
>have "x" amount of variables for all columns in my orders tables, and
>all Columns in my Order Details table. I.e. @OColumn1, @OColumn2,
>@OColumn3, @ODColumn1, @ODColumn2, etc... I would like to create a
>stored procedure to insert into Orders, and have that call another
>stored procedure to insert all the Order details associated with that
>order. The only way I can think of doing it is for the program to pass
>me a string of data per column for order details, and parse the string
>via T-SQL. I would like to get away from the String format, and go
>with something else. If possible I would like the application to
>submit a single value per variable multiple times. If I do it this way
>though it will be running the entire SP again, and again. Any
>suggestions on the best way to solve this would be greatly
>appreciated. If anyone can come up with a better way feel free. My
>only requirement is that it be done in SQL.
>
>Thank you


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 10:08 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com