By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,873 Members | 1,034 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,873 IT Pros & Developers. It's quick & easy.

SQL 2000: Inserting multiple rows into a single table

P: n/a
JB
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
Jul 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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" <JB*******@tampabay.rr.com> wrote in message
news:97**************************@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

Jul 20 '05 #2

P: n/a
JB (JB*******@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, so****@algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #3

P: n/a
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, JB*******@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


Jul 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.