Click here to Skip to main content
15,915,163 members
Home / Discussions / Database
   

Database

 
GeneralRecord is killed after UPDATE Pin
realmontanakid29-Nov-04 11:04
realmontanakid29-Nov-04 11:04 
GeneralRe: Record is killed after UPDATE Pin
realmontanakid29-Nov-04 20:43
realmontanakid29-Nov-04 20:43 
GeneralCopy rows from one table from another Pin
Luis Alonso Ramos29-Nov-04 9:23
Luis Alonso Ramos29-Nov-04 9:23 
GeneralRe: Copy rows from one table from another Pin
Edbert P29-Nov-04 10:56
Edbert P29-Nov-04 10:56 
GeneralRe: Copy rows from one table from another Pin
Luis Alonso Ramos29-Nov-04 11:22
Luis Alonso Ramos29-Nov-04 11:22 
GeneralRe: Copy rows from one table from another Pin
Luis Alonso Ramos30-Nov-04 8:14
Luis Alonso Ramos30-Nov-04 8:14 
GeneralRe: Copy rows from one table from another Pin
Edbert P30-Nov-04 10:49
Edbert P30-Nov-04 10:49 
GeneralRe: Copy rows from one table from another Pin
Luis Alonso Ramos30-Nov-04 13:25
Luis Alonso Ramos30-Nov-04 13:25 
Ok, let's try. I have two sets of tables. When the salesman is working up an order, he captures it in the Quotes table, and its items in the QuoteItems. When the order is accepted, it is copied to the Orders and OrdersItems tables. Most fields are copied the same, but some change (for example the foreign key in QuoteItems is different than that in the OrderItems.)

For the example, the salesman is working with three potential customers, each buying 3 items. The Quotes table has 3 records (for each potential sale) and the QuotesItems has 9 records, 3 for each customer.) The potential sales are saved in the database because it takes some days, and can be edited later if a new requirement is found. Once sent for production, no changes can be made (well, maybe with a phone call.)

Now customer A decides on buying and gives an advance deposit. A new record must be created in Orders and the corresponging three in OrderItems, representing the new real sale, and effectively sending the order for production. Then the quote is marked as been really sold.

I would like to do this in a stored procedure with only one parameter, the PK (ID_quote), and it automatically create the corresponding records in the two analogous tables.

I can already copy the main record in Quotes to Orders (a SELECT into local variables and then an INSERT, and then a SELECT @@IDENTITY to get the new ID_order.) What I cannot do is copy all the records in QuoteItems with ID_quote = @ID_quote (the stored procedure's parameter) and insert them in OrderItems, changing some values (ID_order for example).

I hope its clearer now. Thanks for your help!

-- LuisR



Luis Alonso Ramos
Intelectix - Chihuahua, Mexico

Not much here: My CP Blog!

GeneralRe: Copy rows from one table from another Pin
Edbert P30-Nov-04 15:11
Edbert P30-Nov-04 15:11 
GeneralRe: Copy rows from one table from another Pin
Luis Alonso Ramos30-Nov-04 15:23
Luis Alonso Ramos30-Nov-04 15:23 
GeneralSQL statement help Pin
ruifernandes2429-Nov-04 7:29
ruifernandes2429-Nov-04 7:29 
GeneralRe: SQL statement help Pin
Gerald Schwab29-Nov-04 7:58
Gerald Schwab29-Nov-04 7:58 
GeneralDataSet 2 Xml - element order problem Pin
Xabatcha29-Nov-04 3:18
Xabatcha29-Nov-04 3:18 
QuestionOREIGN KEY REFERENCES? Pin
HahnTech28-Nov-04 12:42
HahnTech28-Nov-04 12:42 
AnswerRe: OREIGN KEY REFERENCES? Pin
Christian Graus28-Nov-04 13:46
protectorChristian Graus28-Nov-04 13:46 
GeneralRe: OREIGN KEY REFERENCES? Pin
HahnTech28-Nov-04 14:54
HahnTech28-Nov-04 14:54 
GeneralRe: OREIGN KEY REFERENCES? Pin
Christian Graus28-Nov-04 18:13
protectorChristian Graus28-Nov-04 18:13 
GeneralRe: OREIGN KEY REFERENCES? Pin
Edbert P28-Nov-04 18:44
Edbert P28-Nov-04 18:44 
GeneralRe: OREIGN KEY REFERENCES? Pin
HahnTech28-Nov-04 23:23
HahnTech28-Nov-04 23:23 
AnswerRe: OREIGN KEY REFERENCES? Pin
Mike Dimmick29-Nov-04 1:00
Mike Dimmick29-Nov-04 1:00 
GeneralRe: OREIGN KEY REFERENCES? Pin
HahnTech29-Nov-04 12:00
HahnTech29-Nov-04 12:00 
AnswerRe: OREIGN KEY REFERENCES? Pin
Chris Meech29-Nov-04 7:16
Chris Meech29-Nov-04 7:16 
GeneralUpdate Statement Pin
jlawren728-Nov-04 12:28
jlawren728-Nov-04 12:28 
GeneralRe: Update Statement Pin
Christian Graus28-Nov-04 13:48
protectorChristian Graus28-Nov-04 13:48 
GeneralRe: Update Statement Pin
Edbert P28-Nov-04 18:39
Edbert P28-Nov-04 18:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.