Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Inserting records to multiple tables using INSERT/SELECT

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-09-23 : 09:36:04
Bill writes "I have three tables, much simplified versions below :

Customers (iPK_CustomerID, tComment)
Notes (iPK_NoteID, tNote)
CustNoteXRef (iPK_XrefID, iFK_CustomerID, iFK_NoteID)

AS you can see, the 3rd table is a cross reference for a many to many relationship between Customers and Notes. The iPK_* columns are primary @@IDENTITY fields, the t* fields are text.

I want to remove the tComment from the Customer table and move the information to the Notes table in a one time script. I've been fooling with:

INSERT INTO Notes (tNote)
SELECT tComment FROM Customers WHERE tComments IS NOT NULL

This works fine, but how do I now add code to also create the Xref table. An INSERT trigger seems to make sense, but I am having trouble figuring out how to get both the Customer and Note IDs I need."

Andraax
Aged Yak Warrior

790 Posts

Posted - 2002-09-24 : 05:05:45
*takes cover* Cursor?

/Andraax

Go to Top of Page
   

- Advertisement -