Write a sql for updating data based on time

Posted by Lu Lu on Stack Overflow See other posts from Stack Overflow or by Lu Lu
Published on 2010-05-05T09:10:05Z Indexed on 2010/05/05 10:48 UTC
Read the original article Hit count: 298

Filed under:
|
|

Hello everyone,

Because I am new with SQL Server and T-SQL, so I will need your help.

I have 2 table: Realtime and EOD. To understand my question, I give example data for 2 tables:

---Realtime table---

Symbol     Date            Value
ABC     1/3/2009 03:05:01   327   // this day is not existed in EOD -> inserting
BBC     1/3/2009 03:05:01   458   // this day is not existed in EOD -> inserting
ABC     1/2/2009 03:05:01   326   // this day is new -> updating
BBC     1/2/2009 03:05:01   454   // this day is new -> updating
ABC     1/2/2009 02:05:01   323
BBC     1/2/2009 02:05:01   453
ABC     1/2/2009 01:05:01   313
BBC     1/2/2009 01:05:01   423

---EOD table---

Symbol     Date            Value
ABC     1/2/2009 02:05:01   323
BBC     1/2/2009 02:05:01   453

I will need to create a store procedure to update value of symbols. If data in day of a symbol is new (compare between Realtime & EOD), it will update value and date for EOD at that day if existing, otherwise inserting.

And store will update EOD table with new data:

---EOD table---

Symbol     Date            Value
ABC     1/3/2009 03:05:01   327
BBC     1/3/2009 03:05:01   458
ABC     1/2/2009 03:05:01   326
BBC     1/2/2009 03:05:01   454

P/S: I use SQL Server 2005. And I have a similar answered question at here: http://stackoverflow.com/questions/2726369/help-to-the-way-to-write-a-query-for-the-requirement

Please help me. Thanks.

© Stack Overflow or respective owner

Related posts about sql

Related posts about sql-server