CREATE OR REPLACE PROCEDURE get123(callType varchar(20) , typeName varchar(30) , timeInterval int(11) NULL, inDate date NULL, site_id varchar(100) ) RETURNS void AS DECLARE
msgType varchar(10) = ‘’;
timeInt int = 1800;
selectInterval varchar(200) = ‘’;
orderBy varchar(50) = ‘hour(time)’;
msgTypeFailure varchar(4) = ‘’;
countSelection varchar(200) = ‘’;
site_id_ varchar (100) = ‘all’;
begin
if(site_id is null or site_id=‘ALL’)
then
set @site_id_ = ‘all’;
else
set @site_id_ = “‘site_id’”;
end if;
if(timeInterval != 3600 and timeInterval != 1800 and timeInterval != 900)
then
timeInt = 3600;
echo select timeInt;
else
set @timeInt = “‘timeInterval’”;
echo select timeInt;
end if;
if (typeName=‘SRISM_INCOMING’)
then
set @msgType = ‘14,15’;
set @msgTypeFailure = ‘14’;
set @countSelection = ’ sum(case when ORIG_MSG_TYPE in (14,15) then COUNT else 0 end) tot,sum(case when ORIG_MSG_TYPE=15 then COUNT else 0 end) succ ';
elseif (typeName=‘SRISM_OUTGOING’)
then
set @msgType = ‘15’;
set @msgTypeFailure = ‘15’;
set @countSelection = ’ sum(case when ORIG_MSG_TYPE=15 then COUNT else 0 end) tot,sum(case when ERROR_CODE=255 then COUNT else 0 end) succ ';
elseif (typeName=‘FWDSM_INCOMING’)
then
set @msgType = ‘16,17’;
set @msgTypeFailure = ‘16’;
set @countSelection = 'sum(case when ORIG_MSG_TYPE in (16,17) then COUNT else 0 end) tot,sum(case when ORIG_MSG_TYPE=17 then COUNT else 0 end) succ ';
elseif (typeName=‘FWDSM_OUTGOING’)
then
msgType = ‘17’;
msgTypeFailure = ‘17’;
countSelection = ’ sum(case when ORIG_MSG_TYPE=17 then COUNT else 0 end) tot,sum(case when ERROR_CODE=255 then COUNT else 0 end) succ ';
end if;
ECHO select countSelection;
ECHO SELECT msgType;
if(timeInt = 3600)
then
set @selectInterval = " CONCAT(CAST(hour(time) AS CHAR(2)),’:00’) as selIntr ";
elseif(timeInt = 1800) then
selectInterval = " CONCAT(CAST(hour(TIME) AS CHAR(2)), ‘:’,(CASE WHEN MINUTE(TIME) < 30 THEN ‘00’ ELSE ‘30’ END)) as selIntr ";
elseif(timeInt = 900) then
set @selectInterval = " CONCAT(CAST(hour(TIME) AS CHAR(2)), ‘:’, ( CASE WHEN MINUTE(TIME) < 15 THEN ‘00’ when MINUTE(TIME) <30 then ‘15’ when MINUTE(TIME) <45 then ‘30’ when MINUTE(TIME)> 45 then ‘45’ end)) as selIntr ";
end if;
echo select selectInterval;
if(callType = ‘RATE’)
then
if(inDate = curdate())
then
ECHO select A.selIntr,A.tot,A.succ ,(A.succ/A.tot)*100 succ_per from (select selectInterval,countSelection from SMS_FIREWALL_SUMMARY where ORIG_MSG_TYPE in (msgType) and (time>(now()-interval 24 hour)) and SITE_ID like (case when(strcmp(‘ALL’,site_id_)) then site_id_ else ‘%’ END) group by selIntr order by hour(time) asc)A ;
else
ECHO select “‘A.selIntr’”,"‘A.tot’","‘A.succ’",("‘A.succ’"/"‘A.tot’")*100 succ_per from (select selectInterval,countSelection from SMS_FIREWALL_SUMMARY where ORIG_MSG_TYPE in (msgType) and (date=inDate) and SITE_ID like (case when(strcmp(‘ALL’,site_id_)) then site_id_ else ‘%’ END) group by “‘selIntr’” order by hour(time) asc) A;
end if;
else
if(inDate = curdate())
then
ECHO select ERROR_CODE,sum(COUNT) count from SMS_FIREWALL_SUMMARY_TEST where ORIG_MSG_TYPE=msgTypeFailure and time > (now() - interval 23 hour) and ERROR_CODE!=255 and SITE_ID like (case when(strcmp(‘ALL’,site_id_)) then site_id_ else ‘%’ END)
group by ERROR_CODE order by count desc ;
else
ECHO select ERROR_CODE,sum(COUNT) count from SMS_FIREWALL_SUMMARY_TEST where ORIG_MSG_TYPE=msgTypeFailure and time > (now() - interval 23 hour) and ERROR_CODE!=255 and SITE_ID like (case when(strcmp(‘ALL’,site_id_)) then site_id_ else ‘%’ END)
group by ERROR_CODE order by count desc;
end if;
end if;
END;
O/P
singlestore> CALL get123(‘RATE’,‘FWDSM_OUTGOING’, 3600,‘2022-10-13’,‘ALL’);
±--------+
| timeInt |
±--------+
| 1800 |
±--------+
1 row in set (0.18 sec)
±---------------------------------------------------------------------------------------------------------------------+
| countSelection |
±---------------------------------------------------------------------------------------------------------------------+
| sum(case when ORIG_MSG_TYPE=17 then COUNT else 0 end) tot,sum(case when ERROR_CODE=255 then COUNT else 0 end) succ |
±---------------------------------------------------------------------------------------------------------------------+
1 row in set (0.18 sec)
±--------+
| msgType |
±--------+
| 17 |
±--------+
1 row in set (0.18 sec)
±------------------------------------------------------------------------------------------------------------+
| selectInterval |
±------------------------------------------------------------------------------------------------------------+
| CONCAT(CAST(hour(TIME) AS CHAR(2)), ‘:’,(CASE WHEN MINUTE(TIME) < 30 THEN ‘00’ ELSE ‘30’ END)) as selIntr |
±------------------------------------------------------------------------------------------------------------+
1 row in set (0.18 sec)
±------------±--------±---------±---------+
| ‘A.selIntr’ | ‘A.tot’ | ‘A.succ’ | succ_per |
±------------±--------±---------±---------+
| ‘A.selIntr’ | ‘A.tot’ | ‘A.succ’ | NULL |
±------------±--------±---------±---------+
1 row in set (0.24 sec)
Query OK, 0 rows affected (0.24 sec)
Thanks In advance