0

I am looking to add the rows 6 and 13 to the results.

enter image description here

SELECT
    ARPDisplayName0

FROM
    v_GS_INSTALLED_SOFTWARE
    
WHERE
    ARPDisplayName0 = 'Adobe Acrobat 9 Pro' or 
    ARPDisplayName0 = 'Bomgar'
John Cappelletti
  • 79,615
  • 7
  • 44
  • 66
My9to5
  • 93
  • 8
  • 1
    As per the question guide, please do not post images of code, data, error messages, etc. - copy or type the text into the question. Please reserve the use of images for diagrams or demonstrating rendering bugs, things that are impossible to describe accurately via text. – Dale K Jul 01 '21 at 20:07
  • 1
    Thats normally a function of the front end. – Dale K Jul 01 '21 at 20:08
  • 1
    Does this answer your question? [Add a summary row with totals](https://stackoverflow.com/questions/17934318/add-a-summary-row-with-totals) – Dale K Jul 01 '21 at 20:08
  • Thanks, Dale, I saw that. But will it add it after each value? – My9to5 Jul 01 '21 at 20:14
  • 1
    Totally lost. Your query returns one column, but your data has two. The `WHERE` clause would generate an error. Please at least put working SQL in the question if it is producing a result set. – Gordon Linoff Jul 01 '21 at 20:14
  • 1
    @My9to5 Check the documentation for `rollup` to see. – Dale K Jul 01 '21 at 20:15
  • @Dale K Rollup definitely looks like its it! Now need to figure out how to SUM/COUNT the nvarchar – My9to5 Jul 01 '21 at 20:22
  • Can you add your expected result here? – Gudwlk Jul 01 '21 at 22:39

1 Answers1

2

I like to use Grouping Sets for such items

Example

Select ARPDisplayName0
      ,ComputerName = coalesce(ComputerName,concat('Total ',sum(1)))
 From  v_GS_INSTALLED_SOFTWARE
 Group By Grouping Sets ( 
                          (ARPDisplayName0,ComputerName)
                         ,(ARPDisplayName0)
                        )

Results

ARPDisplayName0 ComputerName
Acrobat         Comp1
Acrobat         Comp2
Acrobat         Comp3
Acrobat         Total 3
Bomgar          Comp1
Bomgar          Comp2
Bomgar          Total 2
John Cappelletti
  • 79,615
  • 7
  • 44
  • 66
  • Thanks! @YourTable is just a temporary table, right? INSERT INTO is something I've steered away from – My9to5 Jul 01 '21 at 20:25
  • 1
    @My9to5 The (at)YourTable is just a demonstrative table variable -- see updated answer – John Cappelletti Jul 01 '21 at 20:29
  • `CASE WHEN GROUPING(ComputerName) = 1...` instead of the `COALESCE` is probably better, as it returns correct results in the face of nulls. You can also add an `ORDER BY ARPDisplayName0, GROUPING(ComputerName)` to make it neat – Charlieface Jul 01 '21 at 20:48
  • @Charlieface Fair comment. In this case, I suspect the ORDER BY carries a bit more weight. I can't imagine a value of a NULL ComputerName. – John Cappelletti Jul 01 '21 at 21:01