USP_KPI_BBNC_ONLINEREVENUECOUNT
Parameters
Parameter | Parameter Type | Mode | Description |
---|---|---|---|
@VALUE | int | INOUT | |
@ASOFDATE | datetime | IN | |
@DATEFILTER | tinyint | IN | |
@TYPECODES | xml | IN |
Definition
Copy
CREATE procedure dbo.USP_KPI_BBNC_ONLINEREVENUECOUNT
@VALUE int output,
@ASOFDATE datetime,
@DATEFILTER tinyint = null,
@TYPECODES xml = null
as
set nocount on;
if @DATEFILTER is null begin
set @DATEFILTER = 10; -- all dates;
end
declare @GIFTTYPESFILTER table(TYPECODE tinyint primary key);
/*@TYPECODES will not be null if this SP is driven from the UI. Just in case, apply the default value.*/
if @TYPECODES is null begin
insert into @GIFTTYPESFILTER(TYPECODE) values (0)
end else begin
insert into @GIFTTYPESFILTER(TYPECODE) select distinct
T.c.value('(TYPECODEID)[1]','tinyint')
FROM @TYPECODES.nodes('/TYPECODES/ITEM') T(c)
end
declare @STARTDATE datetime;
declare @ENDDATE datetime;
exec dbo.USP_RESOLVEDATEFILTER @DATEFILTER=@DATEFILTER, @STARTDATE=@STARTDATE output, @ENDDATE=@ENDDATE output, @ASOFDATE=@ASOFDATE;
select
@VALUE = count(*)
from
dbo.UFN_BBNC_KPI_ALLREVENUEFORCHANNEL(@STARTDATE, @ENDDATE) as [R]
inner join
@GIFTTYPESFILTER as GIFTTYPESFILTER on GIFTTYPESFILTER.TYPECODE = R.REVENUETYPECODE
if @VALUE is null begin
set @VALUE = 0;
end