CREATE PROCEDURE dbo.xyz @starttime datetime,@endtime datetime
AS
select * into #TempKQMsg from checkinout where userid=1 and left(checktime,10)>=left(@starttime,10) and left(checktime,10)<=left(@endtime,10)
declare @temptime datetime
declare mycursor cursor for select left(checktime,10) from #TempKQMsg where userid=1 group by left(checktime,10)
open mycursor
fetch next from mycursor into @temptime
while @@fetch_status=0
begin
----------------------------------------------------- 不是节假日 -----------------------------------------------------------------------
if((select count(*) from HolidayList where left(Datedays,10)=@temptime)=0)
begin
------------------------------------------------------------不是规定放假------------------------------------------------------------------
if(((select datename(weekday,@temptime))<>'星期六') and ( (select datename(weekday,@temptime))<>'星期日'))
begin
declare @a varchar(10),@atime datetime,@b varchar(10),@btime datetime,@c1 varchar(10),@c1time datetime,@c2 varchar(10),@c2time datetime,@d varchar(10),@dtime datetime,@e varchar(10),@etime datetime
declare @x datetime
select @x='12:30:00.000'
select @x=cast(@temptime+@x as datetime)
select top 1 @a=checkinfo,@atime=checktime from #TempKQMsg where left(checktime,10)=@temptime and checkinfo='A' order by checktime asc
select top 1 @b=checkinfo,@btime=checktime from #TempKQMsg where left(checktime,10)=@temptime and checkinfo='B' order by checktime asc
select top 1 @c1=checkinfo,@c1time=checktime from #TempKQMsg where left(checktime,10)=@temptime and Checkinfo='C' order by checktime asc
select top 1 @c2=checkinfo,@c2time=checktime from #TempKQMsg where left(checktime,10)=@temptime and Checkinfo='C' order by checktime desc
select top 1 @d=checkinfo,@dtime=checktime from #TempKQMsg where left(checktime,10)=@temptime and Checkinfo='D' order by checktime asc
select top 1 @e=checkinfo,@etime=checktime from #TempKQMsg where left(checktime,10)=@temptime and Checkinfo='E' order by checktime asc
----------------------------------------------------------判断情况------------------------
-------------------------------------------------1---------------------
if(@a is not null and @b is not null and @c1 is not null and @c2 is not null and @d is not null and @e is null)
begin
if(@c1time<>@c2time)
begin
if((select count(*) from BcwKQStat where userid=1 and DateTimes=@temptime )=0)
begin
insert into BcwKQStat(UserId,DateTimes,AftOut) values(1,@temptime,'早退:'+cast(@dtime as varchar))
end
end
end
------------------------------------------------1--------------------
---------------------判断情况----------------------------------
end
-------------------------------------------------------------不是规定放假---------------------------------------------------------------------
end
----------------------------------------------------- 不是节假日 -----------------------------------------------------------------------
fetch next from mycursor into @temptime
end
close mycursor
deallocate mycursor
drop table #TempKQMsg
GO我这样写的目的是要统计考勤的信息,在写存储过程的时候,用检查语法没有错误,通过的,可是我调用的时候
exec xyz('2004-06-14','2004-06-16')
这样执行就有错误,===============================
服务器: 消息 170,级别 15,状态 1,行 1
第 1 行: '2004-06-14附近有语法错误。
===============================这是什么原因啊,请高手指教,有什么语法错误
AS
select * into #TempKQMsg from checkinout where userid=1 and left(checktime,10)>=left(@starttime,10) and left(checktime,10)<=left(@endtime,10)
declare @temptime datetime
declare mycursor cursor for select left(checktime,10) from #TempKQMsg where userid=1 group by left(checktime,10)
open mycursor
fetch next from mycursor into @temptime
while @@fetch_status=0
begin
----------------------------------------------------- 不是节假日 -----------------------------------------------------------------------
if((select count(*) from HolidayList where left(Datedays,10)=@temptime)=0)
begin
------------------------------------------------------------不是规定放假------------------------------------------------------------------
if(((select datename(weekday,@temptime))<>'星期六') and ( (select datename(weekday,@temptime))<>'星期日'))
begin
declare @a varchar(10),@atime datetime,@b varchar(10),@btime datetime,@c1 varchar(10),@c1time datetime,@c2 varchar(10),@c2time datetime,@d varchar(10),@dtime datetime,@e varchar(10),@etime datetime
declare @x datetime
select @x='12:30:00.000'
select @x=cast(@temptime+@x as datetime)
select top 1 @a=checkinfo,@atime=checktime from #TempKQMsg where left(checktime,10)=@temptime and checkinfo='A' order by checktime asc
select top 1 @b=checkinfo,@btime=checktime from #TempKQMsg where left(checktime,10)=@temptime and checkinfo='B' order by checktime asc
select top 1 @c1=checkinfo,@c1time=checktime from #TempKQMsg where left(checktime,10)=@temptime and Checkinfo='C' order by checktime asc
select top 1 @c2=checkinfo,@c2time=checktime from #TempKQMsg where left(checktime,10)=@temptime and Checkinfo='C' order by checktime desc
select top 1 @d=checkinfo,@dtime=checktime from #TempKQMsg where left(checktime,10)=@temptime and Checkinfo='D' order by checktime asc
select top 1 @e=checkinfo,@etime=checktime from #TempKQMsg where left(checktime,10)=@temptime and Checkinfo='E' order by checktime asc
----------------------------------------------------------判断情况------------------------
-------------------------------------------------1---------------------
if(@a is not null and @b is not null and @c1 is not null and @c2 is not null and @d is not null and @e is null)
begin
if(@c1time<>@c2time)
begin
if((select count(*) from BcwKQStat where userid=1 and DateTimes=@temptime )=0)
begin
insert into BcwKQStat(UserId,DateTimes,AftOut) values(1,@temptime,'早退:'+cast(@dtime as varchar))
end
end
end
------------------------------------------------1--------------------
---------------------判断情况----------------------------------
end
-------------------------------------------------------------不是规定放假---------------------------------------------------------------------
end
----------------------------------------------------- 不是节假日 -----------------------------------------------------------------------
fetch next from mycursor into @temptime
end
close mycursor
deallocate mycursor
drop table #TempKQMsg
GO我这样写的目的是要统计考勤的信息,在写存储过程的时候,用检查语法没有错误,通过的,可是我调用的时候
exec xyz('2004-06-14','2004-06-16')
这样执行就有错误,===============================
服务器: 消息 170,级别 15,状态 1,行 1
第 1 行: '2004-06-14附近有语法错误。
===============================这是什么原因啊,请高手指教,有什么语法错误
解决方案 »
- SQL2005如何定时执行一个存储过程
- 寻sql语句多表查询
- 用户表有自动编号得UID和用户名,都是唯一得,怎么建索引啊?
- 求SQL语句一条~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- 最近的一个项目需要在一个存储过程中调用另一个存储过程并返回数据集,本人未做过,请大家帮忙,谢谢!
- 请教sql server权限管理
- sql中的时间表达方式,这样正确吗?help!!
- 什么样的SQL语句可以获取数据库中最后10条数据
- 关于SQL7与SQL2000的连接问题,请大家帮忙(在线等)
- 求教关于Update的SQL语句!
- 求助,sql server 2005里面怎么实现2000里面的跨数据库导表功能
- 列行转换,哪个大哥帮我下嘛.
楼上正解!
EXEC 存储过程名 参数1,参数2