Monday, August 15, 2011

Showing a count of items in the Console with SQL

At one point I needed to show a count of items in the console link provided.  To get there I used a format similar to the following and then mapped it accordingly:

"SELECT 'NAME', '(' + CONVERT(VARCHAR(4), COUNT(F.ITEMS)) + ') MY ITEMS' as Due,'',1 as Sort
   FROM TABLE
 UNION 
SELECT 'NAME', '(' + CONVERT(VARCHAR(4), COUNT(F.ITEMS)) + ') MY ITEM LIST TWO' as Due,'',2 as Sort
   FROM TABLE
Order by Sort"

'NAME' is the name of the console branch.
Obviously the convert to varchar is how I'm turning the numerical count into something textual to display.  The actual display with be (count) Name of branch item.  In this case, (#) My Items followed by (#) My Item List Two.

The Union adds the two queries together.  Order seems pretty self explanatory.  So it would look like this in the v9 console:

NAME
   (#) My Items
   (#) My Item List Two

Good for knowing something at a quick glance in the console, such as a number of records, pending tests, and so on.

No comments:

Post a Comment