if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_workday]') and xtype in (N'FN', N'IF', N'TF'))
drop function [dbo].[f_workday]
GO/*--得到指定日期之间的工作日天数--邹建 2004.06(引用请保留此信息)--*//*--调用示例 select dbo.f_workday('2004-06')
--*/
create function f_workday(
@年月 varchar(7) --要查询的年月,格式为:YYYY-MM
)returns int
as
begin
declare @dt_begin datetime,@dt_end datetime
declare @dt datetime,@re int,@i int
select @dt_begin=@年月+'-01',@dt_end=dateadd(month,1,@dt_begin)-1
select @i=datediff(day,@dt_begin,@dt_end)+1
,@re=@i/7*2
,@dt=dateadd(day,@i/7*7-1,@dt_begin)
while @dt<@dt_end
select @re=case when datepart(weekday,@dt) in(1,7)
then @re+1 else @re end
,@dt=@dt+1
return(@i-@re)
end
go
drop function [dbo].[f_workday]
GO/*--得到指定日期之间的工作日天数--邹建 2004.06(引用请保留此信息)--*//*--调用示例 select dbo.f_workday('2004-06')
--*/
create function f_workday(
@年月 varchar(7) --要查询的年月,格式为:YYYY-MM
)returns int
as
begin
declare @dt_begin datetime,@dt_end datetime
declare @dt datetime,@re int,@i int
select @dt_begin=@年月+'-01',@dt_end=dateadd(month,1,@dt_begin)-1
select @i=datediff(day,@dt_begin,@dt_end)+1
,@re=@i/7*2
,@dt=dateadd(day,@i/7*7-1,@dt_begin)
while @dt<@dt_end
select @re=case when datepart(weekday,@dt) in(1,7)
then @re+1 else @re end
,@dt=@dt+1
return(@i-@re)
end
go
解决方案 »
- datetime字段 的 “2008-10-30 15:30:00" 这样的 值,我想在查询语句里的到 这个时间的10分钟之前的值如”2008-10-30 15:20:00“
- 大伙来看看 这个表的设计 有没有问题 欢迎大家发言 顶者有分
- sql server2005学习有哪些好的视频教程?
- SQL求助
- 一个简单的问题?
- 这种查询怎么写?
- t-sql支持这种查询吗?
- 用select * from ##temptable1 返回临时表中的数据,不成功,为什么?
- 各位高人,我在处理两台服务器分布式事务时遇到了如下问题
- 【查询语句问题】统计每个节点最新的一次数据,结果有一个字段随机:
- 关于事务隔离性:
- win2003的几个疑问
set @aa= dbo.f_workday('2004-10')
--set @aa=dbo.f_UDRP_AddNO('BD200405280001',4)
select @aa
结果
----
22
(实际是21天)
加
case 该月有多少天
when 28 then 0 --这个简单,不用说明了。
when 29 then 查该月29日是星期几,如果是1~5,则为1。
when 30 then 查该月29日是星期几,如果是1~4,则为2;若5、7,则1。
when 31 then 查该月29日是星期几,如果是1~3,则为3;若4、7,则为2;其余,则1。
end