开发者

Generate a report every 10 minutes

I have two tables temperature and pressure with readings as shown below my first table generates a value every 10 minutes

The first table contains the following data:

Temperature          Time             Date 开发者_C百科
28.8      1900-01-01 13:14:54.000   2011-05-25 00:00:00
29.1      1900-01-01 13:15:04.000   2011-05-25 00:00:00
29.4      1900-01-01 13:15:14.000   2011-05-25 00:00:00
29.7      1900-01-01 13:15:24.000   2011-05-25 00:00:00
30        1900-01-01 13:15:34.000   2011-05-25 00:00:00
30.3      1900-01-01 13:15:44.000   2011-05-25 00:00:00
30.6      1900-01-01 13:15:54.000   2011-05-25 00:00:00
30.9      1900-01-01 13:16:04.000   2011-05-25 00:00:00
31.2      1900-01-01 13:16:14.000   2011-05-25 00:00:00

My second table generates a value every 20 minutes and i'm storing this value in the database i.e Sql Server

The second table contains

Pressure         Time                  Date
0.9 1900-01-01 13:14:04.000 2011-05-25 00:00:00
1.7 1900-01-01 13:14:24.000 2011-05-25 00:00:00
2.5 1900-01-01 13:14:44.000 2011-05-25 00:00:00
3.3 1900-01-01 13:15:04.000 2011-05-25 00:00:00
4.1 1900-01-01 13:15:24.000 2011-05-25 00:00:00
4.9 1900-01-01 13:15:44.000 2011-05-25 00:00:00
5.7 1900-01-01 13:16:04.000 2011-05-25 00:00:00
6.5 1900-01-01 13:16:24.000 2011-05-25 00:00:00
7.3 1900-01-01 13:16:44.000 2011-05-25 00:00:00

I would like my output to return:

Date          Time       Temperature   Pressure
25/05/2011   13:14:54     28.8           0
25/05/2011   13:15:04     29.1           3.3
25/05/2011   13:15:14     29.4           0
25/05/2011   13:15:24     29.7           4.1

And so on and the user will select particular date on that that date what are the readings are there it should dispaly for example if he select 25/05/2011 that reading should be displayed. I have to bind this result to a gridview using C#.


If you don't mind about possible gaps for missing datetime records, a FULL OUTER JOIN would suffice.

SELECT  ISNULL(t1.Date, t2.Date)
        , ISNULL(t1.Time, t2.Time)
        , ISNULL(t1.Temperature, 0)
        , ISNULL(t2.Pressure, 0)
FROM    Table1 t1
        FULL OUTER JOIN Table2 t2 ON t2.Date = t1.Date AND t2.Time = t1.Time
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜