

/****** Object:  UserDefinedFunction [dbo].[fn_real_num]    Script Date: 2019-06-27 15:49:44 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO






/*±¨¹¤ÊýÁ¿*/
CREATE function [dbo].[fn_real_num](
	@depid int,
	@centerid int,
	@starttime datetime,
	@endtime datetime

)
returns float
as 
	begin
	declare @realnum float
	set @realnum=0
		declare cur cursor for select sum(GenuineNum)  from WorkRecord where [DepId]=@depid and [CenterId]=@centerid and [ReportTime]>=@starttime and [ReportTime]<=@endtime and RecordState=2
	open cur
	fetch next from cur into @realnum
	close cur 
	deallocate cur
	if(@realnum is null)
		set @realnum=0
	return @realnum

	end
GO


