Solarwinds Orion/NPM business hours 95th percentile query

( I'm not sure if this will be generally useful, but I needed it so I thought I'd share in case others may too )

I have a system that uses Solarwinds NPM/Orion to collect interface utilization data from devices scattered around the globe and I found myself needing to calculate 95th percentile values from it that only takes into account local business hours (i.e. no weekends or nights).

After much googling and banging around on the keyboard this is the query that I came up with. As it stands you have to manually adjust the query for the timezones of the SQL database itself and the various devices you're querying, it would be smarter to add a custom field for each device representing its UTC offset and use that value in the query but I haven't made that happen yet

I am certainly no SQL maestro so I've also put it into a github repository in case anyone has ideas on how to improve it or fix any silly mistakes I've made


-- This is a query to calculate 95th percentile statistics for bits in, bits out,
-- and a new column that is the max of bits in vs. bits out for each sample
-- only for business hours (i.e. excluding weekends and hours before / after work
-- hours)