我要生成一个月份的日期列表,像这样日期
2006-6-1
2006-6-2
2006-6-3
2006-6-4
..
..
..
..
一直到
2006-6-30用一个sql语句生成,望各大侠赐教,多谢
2006-6-1
2006-6-2
2006-6-3
2006-6-4
..
..
..
..
一直到
2006-6-30用一个sql语句生成,望各大侠赐教,多谢
解决方案 »
- VC6.0下 C语言开发sql server 2008,新人遇到问题,求解。感谢各位大侠
- 外连接使用了外表的字段两次怎么作啊,说不清进来看吧
- 这两个虚拟机软件Virtaul PC和VMWare Workstation,谁更优秀、更好用又不经常出问题?
- sql语句
- sorry,刚才的语句,邹建是对的,不过移植到以下结构却不对,可能是我问的不对吧,请各位关注
- 谁有winsql的注册码?4.0版本的。
- SQL SERVER数据库崩溃了,紧急求救!!!SOS!!!
- 我想知道如何在SQL server上进行模糊查询功能,具体的sql语句能举个例子吗?
- 毕业设计最终发行版!请各界朋友参与最终的测试!
- 当把服务器的名改了,Microsoft SQL Server就不能正常启动了,为什么?谢谢!!
- 怎么才能够把oracle某个表迁移到sql server中去?
- 请教一个疑似左连接问题
用这个函数,在指定的日期上加一天.循环即OK。
select identity(int,0,1) as id into # from sysobjects
set rowcount 0declare @t table(Date varchar(10))insert into @t select convert(char(10),dateadd(dd,id,'2006-06-01'),120) from # --where datediff(mm,dateadd(dd,id,'2006-03-01'),'2006-03-01')=0select * from @tdrop table #
Times DATETIME)DECLARE
@starttiem DATETIME,
@endtime DATETIMESELECT @starttiem = '2006-1-1',
@endtime = '2006-6-30'WHILE @starttiem <= @endtime
BEGIN
INSERT INTO @t
SELECT @starttiem
SET @starttiem = Dateadd(DAY,1,@starttiem)
ENDSELECT *
FROM @t
select identity(int,0,1) as id into # from sysobjects
set rowcount 0declare @t table(Date varchar(10))insert into @t select convert(char(10),dateadd(dd,id,'2006-06-01'),120) from # where datediff(mm,dateadd(dd,id,'2006-03-01'),'2006-03-01')=0select * from @tdrop table #
declare @i int
declare @date smalldatetime
set @i=1
set @date='2006-6-1'
while @i<>-1
begin
if month(dateadd(day,@i,@date))=month(@date)
begin
print dateadd(day,@i,@date)
set @i=@i+1
end
else
set @i=-1
end
set @BDate ='2006-06-01'
set @EDate = '2006-06-30'select dateadd(day,id-1,@BDate) from (
select id=a.id+b.id*10+c.id*100+d.id*1000+1 from
(
select id=0 union all select 1
union all select id=2 union all select 3
union all select id=4 union all select 5
union all select id=6 union all select 7
union all select id=8 union all select 9
) a,(
select id=0 union all select 1
union all select id=2 union all select 3
union all select id=4 union all select 5
union all select id=6 union all select 7
union all select id=8 union all select 9
) b,(
select id=0 union all select 1
union all select id=2 union all select 3
union all select id=4 union all select 5
union all select id=6 union all select 7
union all select id=8 union all select 9
) c,(
select id=0 union all select 1
union all select id=2 union all select 3
union all select id=4 union all select 5
union all select id=6 union all select 7
union all select id=8 union all select 9
) d
) aa
where id<=datediff(day,@BDate,@EDate)+1
order by id
牛!我要100天就行了,呵呵,这个鱼跟"渔"也差不多了,多谢多谢各位相助