数据库有内容大概形式如下  
 
   日期                           值  
 
2007-05-06                        20  
2007-05-07                        23  
2007-05-09                        15  
2007-05-11                        2  
2007-05-12                        55  
......           
 怎样显示如下形式,把所缺天数的值显示为0  
2007-05-05=0  
2007-05-06=20  
2007-05-07=23  
2007-05-08=0  
2007-05-09=19
2007-05-10=0 
2007-05-11=2  
2007-05-12=55  
......
要求效率高的方法和代码,谢谢各位。

解决方案 »

  1.   

    1.table 显示钱做个循环替换下
    2.查的时候在存储过程做文章
      

  2.   

    cancerser(都是混饭吃,记得要结帖) ( ) 信誉:98  2007-09-17 16:31:02  得分: 0  
     
     
       1.table 显示前做个循环替换下
    2.查的时候在存储过程做文章  
     
    -------------------------------
    正解
      

  3.   

    http://community.csdn.net/Expert/topic/5761/5761870.xml?temp=.378338
      

  4.   

    cancerser(都是混饭吃,记得要结帖)
    gisfarmer(菜菜阿杰)能否把存储过程代码帖出来
      

  5.   

    直接SQL语句组合:select (CAST(日期 AS nvarchar(20)) + '=' + CAST(值 AS nvarchar(10))) FROM TABLE1
      

  6.   

    TABLE1 是你的表名select (CAST(日期 AS nvarchar(20)) + '=' + CAST(值 AS nvarchar(10))) FROM TABLE1 order by 日期
      

  7.   

    sql语句+动态生成
    select 日期,值  from 表
    while(dr.read)
    {
       创建动态控件 ... 付值
    }
      

  8.   

    create table ta(日期 datetime,值 varchar(5))
    insert ta  
    select  '2007-01-02', '45'
    union all select  '2007-01-01' , '12'
    union all select  '2007-01-04' , '24'生成一个时间段列:
    declare @ta table(t_date datetime)
    declare @i datetime
    set @i='2007-01-01 00:00:00'
    while @i!>'2007-1-31 00:00:00'
    begin
    insert @ta select convert(varchar(10),@i,120)
    select @i=@i+1
    endselect convert(varchar(10),t_date,120)+' = '+isnull(值,0) from @ta a , ta 
    where convert(varchar(10),t_date,120)*=convert(varchar(10),"日期",120)
    and convert(varchar(10),t_date,120) between '2007-01-02'and '2007-01-31'
      

  9.   


    //各种数据库的SQL语句有些不同,这个是oracle
    select concat(concat(a1,'='),a2) from 
    (
    select cast(日期 as varchar(20 )) a1 ,cast(值 as varchar(20)) a2
    from 表
    )//如果要对值进行空值的判断,可以使用case when ,查一下它的用法吧
      

  10.   

    我觉的可以建军一个一样的表
    tempDeclare @begindate datetime
    Declare @enddate datetime
    set @begindate ='2007-05-05'
    set @enddate ='2007-06-05'select * into temp from 原表WHILE (@begindate < @enddate )
    BEGIN
    --要求效率这里可以判断一下@begindate在原表是否存在,不存在再添加
         INSERT INTO temp VALUES
        
             (@begindate ,0)
             
          SET @begindate = @begindate + 1
      
    END
    select 日期,sum(值) as 值 from 
    temp group by 日期
    drop temp
      

  11.   

    非常感谢各位的回复,我的问题解决了
    采用表对比的方法left JOIN然后isnull(#t1.值,0)谢谢各位了