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 ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| 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 |
| |||
| 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 |
| |||
| 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 |
| ||||
| 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 |