Query to find the Consumed Units (Charge by Requests / Hour) (PGSQL & MSSQL)

Query to find the Consumed Units (Charge by Requests / Hour) (PGSQL & MSSQL)

Tested in Build PGSQL (14300) or MSSQL (14306)


Go to Reports Tab >> New Query Report >> Run the below query 

Consumed units (Charge by Requests) :

PGSQL & MSSQL:

select ad.org_name "Account",sp.serviceplanname "Service Plan",longtodate(ac.startdate) "Start Date", longtodate(ac.expirydate) "Expiry Date",COUNT(wo.workorderid) "Consumed number of Requests",MAX(sp.fixedmonthlyunits)-MAX(bc.consumedunits) "Requests Remaining" from workorder wo LEFT JOIN workorderstates wos on wo.workorderid = wos.workorderid LEFT JOIN statusdefinition sd on sd.statusid = wos.statusid left join accountsitemapping asm on asm.siteid = wo.siteid inner join accountcontract ac on ac.accountid = asm.accountid left join serviceplan sp ON ac.serviceplanid=sp.serviceplanid left join billcycle bc ON ac.contractid=bc.contractid Left join accountdefinition ad on asm.accountid = ad.org_id where ac.isactivecontract ='true' and sd.internalname= 'Closed' and plantype='Charge Per Incident' group by ad.org_name,ac.startdate,ac.expirydate,sp.serviceplanname ********************************************************************************************************

Consumed units (Charge by Hour) :

PGSQL & MSSQL:

select ad.org_name "Account",sp.serviceplanname "Service Plan",longtodate(ac.startdate) "Start Date", longtodate(ac.expirydate) "Expiry Date", (MAX(bc.consumedunits)/3600000) "Hours Used",MAX(sp.fixedmonthlyunits)-(MAX(bc.consumedunits)/3600000) "Hours Remaining" from workorder wo LEFT JOIN workorderstates wos on wo.workorderid = wos.workorderid LEFT JOIN statusdefinition sd on sd.statusid = wos.statusid left join accountsitemapping asm on asm.siteid = wo.siteid inner join accountcontract ac on ac.accountid = asm.accountid left join serviceplan sp ON ac.serviceplanid=sp.serviceplanid left join billcycle bc ON ac.contractid=bc.contractid Left join accountdefinition ad on asm.accountid = ad.org_id where ac.isactivecontract ='true' and sd.internalname= 'Closed' and plantype='Charge Per Hour' group by ad.org_name,ac.startdate,ac.expirydate,sp.serviceplanname ********************************************************************************************************

                  New to ADSelfService Plus?