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.
| Author |
Topic |
|
nickfinity
Yak Posting Veteran
55 Posts |
Posted - 2004-05-21 : 11:29:39
|
| Hello,I'm sure this is a dumb question and has been answered many times, but I can't find it or figure out the easiest way to do it. I have three tables (simplified):Person(id, name)Position(personid, title)temp(name, title)Basically I want insert the records from temp into person and position. What's the best way to do this? Thanks for your help, I really appreciate it.Thanks,Nick |
|
|
stephe40
Posting Yak Master
218 Posts |
Posted - 2004-05-21 : 11:38:34
|
| If your IDs are identities it will be a slight problem. Your going to have to use a cursor to loop through temp table doing an insert into person, grabbing that id and then doing the insert into position with the id you just got.Heck, It might be best to add a id field to the temp table and fill it with identity values and then run this query:insert into person (id, name)select (tempid, name)insert into position(personid, title)select(tempid, title)Its up to you.. depeding on your flexibility with the temp table.- Eric |
 |
|
|
nickfinity
Yak Posting Veteran
55 Posts |
Posted - 2004-05-21 : 11:46:20
|
| Thanks for your help Eric. Personid is an identity field. I don't think I can add an id field to temp. I thought I might have to use cursors. I've never really used them much, so I was hoping there might be another way. Oh well, a good opportunity to learn something. Thanks again for your help. |
 |
|
|
|
|
|
|
|