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 |
|
dreardon
Starting Member
2 Posts |
Posted - 2007-07-05 : 01:41:05
|
| I'm having a problem with the logic in a SQL query that I need to run.I'm selecting 4 columns from an each record in my old database and inserting 2 into tableA and 2 into tableB of a new database. TableA and tableB both have identities on with the self-incrementing values, albeit they are starting at different numbers due to old data. As shown below, I need to get the ID number of the row entered in tableA in order to populate a pointer field in tableB. How should I write the SQL query. My example below is basically pseuocode since I'm sure I'm pretty far off. I've played around with @@IDENTITY, but can't get it to work.INSERT INTO DB1.dbo.tableAvalues(valA, valB)INSERT INTO DB1.dbo.tableBvalues([unique id entered in the first insert], valC, valD)SELECT valA, valB, valC, valDfrom DB2.dbo.usersCan someone help me with this? Thanks.Dan |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2007-07-05 : 01:47:24
|
| [code]INSERT INTO DB1.dbo.tableBvalues(Scope_Identity(), valC, valD)[/code]Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
dreardon
Starting Member
2 Posts |
Posted - 2007-07-05 : 19:21:44
|
| Thanks for the help. |
 |
|
|
|
|
|