title: Best way of handling if a>b in a case
body: <p>Is there a better way of writing the following chunk of a query?</p>
  
  <pre><code>CASE WHEN ugt.Type = 'Permanent' 
              AND ISNULL(ug.lastpromotion,u.CreatedOn) &lt; DATEADD(MM,-6,GETDATE())
          THEN 
              (
                  SELECT  cast(sum(pc.CommissionPerc / 100) as numeric(3,1))
                  FROM Placements p
                  INNER JOIN PlacementConsultants pc on pc.PlacementId = p.PlacementID AND pc.UserId = @userid
                  INNER JOIN PlacementInvoices PlI on PlI.PlacementID = P.Placementid
                  WHERE p.CreatedUserId = @userid
                  AND pli.CreatedOn 
                          BETWEEN DATEADD(MM,-6,GETDATE())
                          AND GETDATE()
              )
      WHEN ugt.Type = 'Permanent' 
              AND ISNULL(ug.lastpromotion,u.CreatedOn) &gt; DATEADD(MM,-6,GETDATE())
          THEN 
              (
                  SELECT cast(sum(pc.CommissionPerc / 100) as numeric(3,1))
                  FROM Placements p
                  INNER JOIN PlacementConsultants pc on pc.PlacementId = p.PlacementID AND pc.UserId = @userid
                  INNER JOIN PlacementInvoices PlI on PlI.PlacementID = P.Placementid
                  WHERE pc.UserId = @userid
                  AND pli.CreatedOn 
                          BETWEEN ISNULL(ug.lastpromotion,u.CreatedOn)
                          AND GETDATE()
              )
  END
  </code></pre>
  
  <p>As all that's changing is the pli.createdon needs to use the most recent out of the last promotion or 6 months ago. (i.e. count the number of deals since their latest promotion or 6 months ago, whatever is the most recent)?</p>
  
  <p>Or am I stuck doing 2 cases for each type?</p>