I have a update statement that will change the state in a tableA from TableB. The data in this table is like:
Serial PersonId Date Department State Begintime Endtime
1 1 2012-01-01 50 1 08:00 11:00
2 1 2012-01-01 50 5 11:00 14:00
When I get State 2 from tableB then I need to set the states of the both records to: 2 but I want have just one record for each state.
The result should be:
Serial PersonId Date Department State Begintime Endtime
1 1 2012-01-01 50 2 08:00 14:00
Vice versa also must be possible:
TableA contains:
Serial PersonId Date Department State Begintime Endtime
1 1 2012-01-01 50 2 08:00 14:00
After the update I would like to have: (this two records are coming from tableB)
Serial PersonId Date Department State Begintime Endtime
1 1 2012-01-01 50 1 08:00 10:00
2 1 2012-01-01 50 5 12:00 15:00
I also don't know if this need to be updated with a update statement.
Any ideas to solve this?
I'm using sql server 2005.