解决方案 »

  1.   

    还是交给乌龟来做好了 oracle的不会啊
      

  2.   


    --参考这个
    /*====================================================*/
    -- Author: Ken Wong
    -- Create date: 2009-12-17 10:44:49
    -- Description:
    /*====================================================*/
    /*
    dbo.proc_trans_makedata '@table
    id        day        starttime        overtime        name 1    20091202        9:00              16:00        张三 
    '
    */
    /*
    例子描述问题: 
    表  t1 , 内容: -------------------------------------------------------------- 
    id        day        starttime        overtime        name 1    20091202        9:00              16:00        张三 
    ----------------------------------------------------------------- 查询条件:20091129 - 20091205, 写一条 SQL 语句得到下面的表: ------------------------------------------------------------------------------------ 
        时间    星期日  星期一  星期二  星期三  星期四  星期五  星期六 
    8:00-9:00    null    null  null    null    null  null  null 
    9:00-10:00    null    null  null    张三    null      null      null 
    10:00-11:00  null    null    null    张三    null      null      null 
    11:00-12:00  null    null    null    张三    null      null      null 
    13:00-14:00  null    null    null    张三    null      null      null 
    14:00-15:00  null    null    null    张三    null      null      null 
    15:00-16:00  null    null    null    张三      null      null      null 
    16:00-17:00  null    null    null    null    null      null      null 
    17:00-18:00  null    null    null    null    null      null      null */
    --> 测试数据:@table
    declare @table table([id] int,[day] varchar(10),[starttime] varchar(10),[overtime] varchar(10),[name] varchar(10))
    insert @table
    select 1,'20091202', '09:00','16:00','张三'
    declare @begdate datetime,@enddate datetime
    select @begdate = '20091129',@enddate = '20091205'select t.[date],t.[time],u.[name] into #temp from
    (
    select convert(varchar(10),dateadd(hour,number,@begdate),112) as [date],
    convert(varchar(10),dateadd(hour,number,@begdate),108) + '-'
    +convert(varchar(10),dateadd(hour,number+1,@begdate),108) as [time],
    null as [name]
    from master.dbo.spt_values
    where type = 'P' 
    and dateadd(hour,number,@begdate) <= dateadd(hour,18,@enddate)
    and convert(varchar(10),dateadd(hour,number,@begdate),108) >= '08:00'
    and convert(varchar(10),dateadd(hour,number,@enddate),108) <= '18:00'
    ) t left join 
    (
    select convert(varchar(10),dateadd(hour,r.number,@begdate),112) as [date],
    convert(varchar(10),dateadd(hour,number,@begdate),108) + '-'
    +convert(varchar(10),dateadd(hour,number+1,@begdate),108) as [time],
    h.name
    from master.dbo.spt_values r ,@table h 
    where type = 'P' 
    and convert(varchar(10),dateadd(hour,number,@begdate),108) >= h.[starttime]
    and convert(varchar(10),dateadd(hour,number,@enddate),108) <= h.[overtime]
    and convert(varchar(10),dateadd(hour,r.number,@begdate),112) = h.[day]
    ) u
    on t.[date] = u.[date] and t.[time] = u.[time]--select * from #tempdeclare @sql varchar(8000)
    select @sql = ''select @sql = @sql + ',max(case [date] when '+[date]+' then name else null end) as ['+ltrim(datename(weekday,[date]))+']'
    from (select distinct [date] from #temp) tselect @sql = 'select [time] '+ @sql + ' from #temp group by [time]'--print @sqlexec(@sql)drop table #temp
      

  3.   

    呵呵 sql server 实现也行啊 我自己转换