日期:2014-05-18  浏览次数:20669 次

求SQL语句,急阿!!!!
有一张表是这样的,
workTable(id(主键,自动增长),work_name,work_date,work_content,status)
数据:
1,张三,2012-06-23,test, 0
2,张三,2012-06-24,test2,0
3,张三,2012-06-26,test4,0

我想查询出23号到26号的数据,格式如下:
张三 2012-06-23 test 0
张三 2012-06-24 test2 0
null null null null 
张三 2012-06-26 test4 0

25号是没数据的,我想显示出来。

麻烦各位了,小弟我SQL实在很老火。

------解决方案--------------------
改了一下
SQL code

select * into #workTable from (
select 1 as id ,'张三' as work_name,'2012-06-18' as work_date,'test' as work_content, 0 as status
union
select 2,'张三','2012-06-22','test2',0
union
select 3,'张三','2012-06-26','test4',0
union
select 4,'张三','2012-06-28','test4',0
union
select 5,'张三','2012-06-30','test4',0) a


while exists(select 1 from #workTable where dateadd(day,1,work_date) not in (select work_date from #workTable)
and ID <> (select MAX(id) from #workTable))
begin
insert into #workTable 
select id,'',convert(varchar(10),dateadd(day,1,work_date),120),'',0
from #workTable
where dateadd(day,1,work_date) not in (select work_date from #workTable)
and ID <> (select MAX(id) from #workTable)
end

select * from #workTable order by ID,work_date