This discussion has been locked. The information referenced herein may be inaccurate due to age, software updates, or external references.
You can no longer post new replies to this discussion. If you have a similar question you can start a new discussion in this forum.

Group Availability Search Widget

Hey Guys! Quick question for anyone willing.

I am trying to make a search widget that will allow a user to input a group name and then it will display the Name of the group along with its availability over the last 30 days.

So far I have this:

SELECT Container.DisplayName, AVG(ContainerStatus.PercentAvailability) AS AVERAGE_Last_30_Days, Primary_ISP, Secondary_ISP

FROM Orion.ContainerStatus

INNER JOIN Orion.Container

ON ContainerStatus.ContainerID = Container.ContainerID

INNER JOIN Orion.GroupCustomProperties

ON ContainerStatus.ContainerID = GroupCustomProperties.ContainerID

WHERE DisplayName LIKE '%${SEARCH_STRING}%' AND DATETIME >=ADDDATE('day',-30, GETDATE())

It works really well, however I am having an issue with formatting.  I would like the output of the AVG to round to at least 2 decimal places and right now it is only giving me whole numbers. I essentially want to be able to make the format look like {0:0.00} unit/% that but I am unsure of the syntax or if it is even possible. If anyone has any ideas about this, please let me know!!

  • It looks like you might have some mutually exclusive stuff going on here.

    What you have will work for SWQL and is necessary for the search portion of the widget, however, I believe the reason why you're not getting decimal points like you desire is due to the data type being INT instead of FLOAT.

    So you could resolve this by using a SQL query and using round(avg(cast(percentavailability as float)), 2) for your data set, but CAST isn't supported for SWQL.

    So you may have to decide if you need the precision or the searching functionality there.

  • Hey!

    Thanks for the answer!

    After messing around with it I was actually able to do this: ROUND(AVG(ContainerStatus.PercentAvailability*1.00), 2)

    From what I found, it defaults to a whole integer but by multiplying it by 1.00 I was able to have it give me the full number and then used the round command to narrow it to two spaces!

  • Nice, thanks for sharing. I had played around with the logic some, but not  thought to force the decimal conversion, good work!