0 Replies Latest reply on Mar 16, 2015 9:22 AM by Oliver Jen

    where clause based on filter value?

    Oliver Jen

      Hi,

       

        I have a child table (~1.2B rows) that I need grouped (and a COUNT), but I'd like to do it based on a filter that's applied to a parent table.  To illustrate;

       

      This is very slow:

      SELECT IdValue, COUNT(*) as SuccessCount

      FROM TableSuccesses

      GROUP BY IdValue

       

      This is very fast:

      SELECT COUNT(*)

      FROM TableSuccesses

      WHERE IdValue = @IdValue


      The IdValue is the singleton value selected from a drop down filter.  Is this possible? 


      I can start researching fancier in-database solutions, but if there were some way to "defer" the query to TableSuccesses until after a filter was selected, that would make my life much easier.


      Thx,

      Oliver.