首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

关于SQL求指定月度天数及工作日天数

2012-09-29 
关于SQL求指定月份天数及工作日天数sql 求指定月份天数?SQL 求指定月份工作日天数?[解决办法]SQL code--指

关于SQL求指定月份天数及工作日天数
sql 求指定月份天数?
SQL 求指定月份工作日天数?

[解决办法]

SQL code
--指定月份天数declare @m varchar(7)set @m='2012-08'select datediff(day,@m+'-01',dateadd(month,1,@m+'-01'))--指定月份工作天数declare @dt datetime,@dt2 datetime,@i intset @dt=convert(datetime,@m+'-01')set @dt2=dateadd(month,1,@dt)while @dt<@dt2begin    if datepart(weekday,@dt)<>1 and datepart(weekday,@dt)<>6        set @i=isnull(@i,0)+1    set @dt=dateadd(day,1,@dt)    endselect @i
[解决办法]
SQL code
create  function getWorkDays( @year int , @month int )returns int as begin     declare @CountDay int      declare @temptime datetime    set @CountDay = 0     set @temptime = convert(varchar,@year) + '-'+ convert(varchar,@month) + '-01'      while(MONTH(@temptime) = @month)     begin         if DATEPART(weekday,@temptime) <>1 and DATEPART(weekday,@temptime)<>7          begin             set @CountDay = @CountDay + 1            End        set @temptime = DATEADD(day,1,@temptime)     end    return @CountDayend --调用select dbo.getWorkDays(2009,7) 

热点排行