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 |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2006-12-15 : 07:57:15
|
| Soorej writes "I have a subscriber table with fields of my interest as ID,subscriber_id,status,rateplan, plan_start_date,plan_end_date,term_date ID is the pk,, there can be many entries with the same subscriber_id as and when he chnges the rateplan . But there will be a record with plan_end_date as an infinite date. Also the term_date will be infinite in this case.. Then I have a temp_subscriber table with the same structure. In this I have the updates for the subscriber table. I have to compare the data in this temp_subscriber table with the subscriber table.. If the same record exists in the subscriber table . No alteration to subscriber table If there is record with the same subscriber_ID but a change in status or rateplan then update the plan_end_date of subscriber table with plan_start_date in temp_subscriber table also insert this record in temp_subscriber table to subscriber table ( Update + Insert) If the record in temp_subscriber table is not in subscriber table just insert the record .. ( Records are compared using subscriber_id field )This is to be done in MS SQL Server 2005" |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-12-15 : 10:08:30
|
| General approachUpdate t1set col=t2.col,..from table1 t1 inner join table2 t2on t1.keycol=t2.keycolInsert into table1(cols)Select cols from table2 t2where not exists(select * from table1 where keycol=t2.keycol)MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|