Thursday, March 29, 2012

Cursor required for update?

Hello All,

I am trying to determine the most efficient way of performing an update and am new to SQL Server. Here's what I am trying to do:

1. Get max of numerical address_ID field in Table 1.
2. Update records in Table 2 where homeadd_id is null with results from #1, plus 1 to increment.
3. Back to Table 1 to append a new record with newest homeadd_id number, plus fill in a couple of fields in that row.
4. Continue until all records from 2 are filled in.

I hope that this is clear enough - sorry, it's been a long time since I've coded anything and am just getting my feet wet.

Thanks for any advice.
CarmenYour approach doesnt seem correct.
As soon as you update everything to a new number that is null in table 2 it would be nothing more to update so it can be done only once.
The correct way would be insert record into table 1 with max(address_id) + 1 after record inserted go for inserting records into table 2 with new address_id.

Hope I understood your question correctly.

Good Luck.sql

No comments:

Post a Comment