‘时间'字段是DATETIME型,利用DBCHART控件来显示数据,X轴显示时间,但是是以小时
显示如:9:00,10:00,11:00............的显示格式,SQL应该怎么写!

解决方案 »

  1.   

    DATEADD
    在向指定日期加上一段时间的基础上,返回新的 datetime 值。语法
    DATEADD ( datepart , number, date ) 
      

  2.   

    SELECT DATEADD(hour, 1, getdate()) AS timeframe
      

  3.   

    Select Time('时间') form table 不知道行不行,能不能说清楚点。如果要想通过SQL语句直接生成9:00,10:00,11:00............好像不大可能。应该读取完之后在Delphi中处理一下:使用DecodeDateTime
      

  4.   

    SELECT DATEDIFF(day, '2003-05-05 12:00:00', getdate())
      

  5.   

    因为我是用DBCHART1的X轴显示的,DecodeDatetime怎样实现?series.xvalues.valuesourc:='时间',所以要在SQL中直接生成
      

  6.   

    select Value1,Month('时间') 
    from table 
    where .....series.xvalues.valuesourc:='时间'
    series.yvalues.valuesourc:='value1'
      

  7.   

    myyanghua(水手) 看清了题意,可惜要用SQL来实现
      

  8.   

    楼主注意
    x轴必须是字符型
    我上面的代码已经可以给楼主足够的提示了chart组件的实现如下 可以参考
    chart.series[0].add(1,inttostr(1));
    这条语句显示点(1,1)
      

  9.   

    declare @i  int ,
            @selectStr Varchar(5005),
            @j Varchar(2)
    set @i=0 
    set @j='0'
    set @selectStr='select ' 
    while @i<=24  
    begin
      if @i<24 
      set  @selectStr=@selectStr+' datepart(hh,''00:00'')+'+@j+' As T'+@j+' ,'
      else
      set  @selectStr=@selectStr+' datepart(hh,''00:00'')+'+@j+' AS T'+@j    Set @i=@i+1
      set @j=Cast(@i As varchar(2)) 
    end
    exec(@selectStr)
    结帖吧
      

  10.   

    慢着,再改进一下:declare @i  int ,
            @selectStr Varchar(5005),
            @j Varchar(2)
    set @i=0 
    set @j='0'
    set @selectStr='select ' 
    while @i<=24  
    begin
      if @i<24 
      set  @selectStr=@selectStr+'(Cast( datepart(hh,''00:00'')+'+@j+' As Varchar(6))+'':00'')  As T'+@j+' ,'
      else
      set  @selectStr=@selectStr+'(Cast( datepart(hh,''00:00'')+'+@j+' as Varchar(6))+'':00'')  AS T'+@j    Set @i=@i+1
      set @j=Cast(@i As varchar(2)) 
    end
    exec(@selectStr)