如果我要查询过去仪器1,6,24小时记录的数据该怎么写,还有任意两个时间点datetime间的数据又该如何写呢
我下面给出一小段代码,请各位大侠帮忙修改下实现以上的要求,谢谢指教……
create proc historydata
@stationid tinyint,
@starttime datetime,
@overtime datetime
as
begin
select Temperature,AirPressure,Humidity,WindDirection,WindSpeed,RainFall,WeatherPhenomenonName,StartTime,OverTime
from SixFactors
join WeatherPhenomenon on WeatherPhenomenon.WeatherNO = SixFactors.WeatherNO
where SixFactors.StationID = @stationid and DATEDIFF(SixFactors.CollectDate,@starttime,@overtime)
go

解决方案 »

  1.   

    1,6,24小时记录的数据该怎么写,还有任意两个时间点datetime间的数据又该如何写
    select * from tb where rowtime< dateadd(timeclumn,h,-1);
    select * from tb where rowtime< dateadd(timeclumn,h,-6);
    select * from tb where rowtime< dateadd(timeclumn,h,-24);select * from tb where rowtime between '2011-12-26 00:00:00' and ''2011-12-27 00:00:00'
      

  2.   

    create proc historydata
    @stationid tinyint,
    @starttime datetime,
    @overtime datetime
    as
    begin
    select Temperature,AirPressure,Humidity,WindDirection,WindSpeed,RainFall,WeatherPhenomenonName,StartTime,OverTime
    from SixFactors
    join WeatherPhenomenon on WeatherPhenomenon.WeatherNO = SixFactors.WeatherNO
    where SixFactors.StationID = @stationid and SixFactors.CollectDate BETWEEN @starttime AND @overtime
    go