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 |
|
bluemetal
Starting Member
26 Posts |
Posted - 2005-07-17 : 22:19:36
|
| Hi Guys:I have a question if this can be done?- Can i update table1 within a daterange with some value, and simultaneously update another table2 with another value but only for records that have been updated in table1? I do have a common identifier between two tables.Can this be done in 1 single query, or there is more need to it? SP?Heres my eg:Table 1 : I update table1 within a DATE RANGE any number of records with a value, this results in 100 records (for eg) being updated each with a Policy_NumberTable 2: Now i need to update table2 with a value with policy_numbers equaling the ones updated in table1 I hope this is clear enuf! Thankyou. |
|
|
timmy
Master Smack Fu Yak Hacker
1242 Posts |
Posted - 2005-07-17 : 23:25:48
|
I don't think you can update 2 tables with one statement. But it should be easy enough to do using a stored procedure (the best place for these sorts of operations anyway...)UPDATE table1 SET field = @newValue WHERE dateCol BETWEEN @startDate and @endDateUPDATE table2 SET anotherField = @anotherValue WHERE policy_number IN (SELECT policy_number FROM table1 WHERE dateCol BETWEEN @startDate and @endDate You could also do this using triggers if you wanted to.HTH,Tim |
 |
|
|
bluemetal
Starting Member
26 Posts |
Posted - 2005-07-18 : 00:41:20
|
| Thanks! I did just the same :) |
 |
|
|
|
|
|