执行统计的存储过程 Alter Proc [dbo].[getday] @year varchar(4), @month varchar(2), @cardNo varchar(50), @kg float output, --旷工 state=3 @zt float output, --早退 state=4 @bj float output, --病假 state=5 @sj float output, --事假 state=6 @zcxj float output, --正常休假 satate=7 @qt float output --其它休假 state=8 as begin declare @days float declare @leaveType int declare @state int Set @state=3 while @state<9 begin set @days=0 declare c cursor for Select leavetype From T_dutyLog Where left(dutydate,2)=@month and substring(convert(varchar,dutydate),7,4)=@year and CardNo=@cardNo and state=@state; open c fetch next from c into @leaveType While @@FETCH_STATUS=0 begin if @leaveType=0 begin set @days=@days+1; end if @leaveType=1 begin set @days=@days+0.5; end if @days=2 begin set @days=@days+0.5; end fetch next from c into @leaveType end Close c DEALLOCATE c if @state=3 begin Set @kg=@days end if @state=4 begin Set @zt=@days end if @state=5 begin Set @bj=@days end if @state=6 begin Set @sj=@days end if @state=7 begin Set @zcxj=@days end if @qt=8 begin Set @bj=@days end set @state=@state+1 end end 在SQL中执行该存储过程! declare @kg float declare @zt float declare @bj float declare @sj float declare @zcxj float declare @qt float exec getday '2009','07','02334474',@kg output,@zt output, @bj output ,@sj output,@zcxj output,@qt output print @kg print @zt print @bj print @sj print @zcxj print @qt