写一个列举一月内所有日期的视图
求各位帮忙
[解决办法]
--定义变量,赋值为当前日期declare @t datetime set @t=getdate()select distinct datecol from tablename where convert(varchar(7),datecol,120)=convert(varchar(7),@t,120)
[解决办法]
create view GetdtViewaswith Getdtas ( select cast(convert(varchar(7),getdate(),120)+'-01' as datetime) dt union all select dateadd(day,1,dt) from Getdt where dt<dateadd(day,-1,convert(char(07),dateadd(month,1,getdate()),120)+'-01') )select * from Getdt
[解决办法]
select dateadd(day,number,convert(varchar(7),DATEADD(MONTH,-1,GETDATE()),120)+'-01')dt
from master..spt_values
where type='P' and number<day(dateadd(day,-1,convert(char(07),dateadd(month,1,DATEADD(MONTH,-1,GETDATE())),120)+'-01'))
[解决办法]
create view VwGetDateas select dateadd(dd,number,DATEADD(m,-1,getdate())) AS date from master..spt_values where type='p' and dateadd(dd,number,DATEADD(m,-1,getdate()))<=GETDATE()