title: Count of one if there are more than one entry in the result?
body: <pre><code>DECLARE @StartDate AS SMALLDATETIME
  DECLARE @EndDate AS SMALLDATETIME
  DECLARE @BranchNum AS INT
  
  SET @StartDate = '2019-10-22'
  SET @EndDate = '2019-10-23'
  set @BranchNum = '4'
  
  SELECT DISTINCT s.branch AS [Branch], s.CREATEDBYUSER AS [Teller Number],
  acct.accountnumber AS [Account Number],
  COUNT(DISTINCT CASE WHEN s.CLOSEDATE is null 
                          AND s.CHARGEOFFDATE is NULL
                          AND (s.OPENDATE &gt;= @StartDate AND s.OPENDATE &lt;= 
  @EndDate)
                     then s.PARENTACCOUNT
                     END
      ) AS [Shares],
  CASE WHEN s.CLOSEDATE is null 
           AND s.CHARGEOFFDATE is NULL 
      THEN s.balance 
      else 0
  END AS [SharesBalance],
  CASE WHEN s.CLOSEDATE is null 
           AND s.CHARGEOFFDATE is NULL
      THEN s.TYPE
      ELSE 0
  END AS [Share Type],
  CASE WHEN s.CLOSEDATE is null
           AND s.CHARGEOFFDATE is NULL
      then s.DESCRIPTION 
      ELSE NULL
      END AS [Share Description],
  CASE When c.TYPE in (15,16,17) 
           AND c.STATUS = 1 
           AND c.CLOSEDATE is null 
           AND (c.ISSUEDATE &gt;= @StartDate AND c.ISSUEDATE &lt;= @EndDate)
      THEN 1
      ELSE 0
  END AS [Debit]
  from ARCUSYM000.dbo.ACCOUNT acct
  INNER join ARCUSYM000.dbo.savings s
      on acct.ACCOUNTNUMBER = s.PARENTACCOUNT
      and s.ProcessDate = acct.ProcessDate
  INNER join arcuSYM000.dbo.CARD c 
      on acct.ACCOUNTNUMBER = c.PARENTACCOUNT
      and c.ProcessDate = acct.ProcessDate
  where acct.CLOSEDATE is null  
      AND s.CLOSEDATE is null 
      AND s.chargeoffdate is null 
      AND (
          (s.OPENDATE &gt;= @StartDate AND s.OPENDATE &lt;= @EndDate)
          OR (acct.OPENDATE &gt;= @StartDate AND acct.OPENDATE &lt;= @EndDate)
          )
      AND acct.memberstatus = 0 
      AND s.branch is not null 
      AND s.branch = @BranchNum
      AND s.ProcessDate = CONVERT(VARCHAR(8), dateadd(day,-1, getdate()), 112)
      AND acct.ProcessDate = CONVERT(VARCHAR(8), dateadd(day,-1, getdate()), 
  112)
     AND c.ProcessDate = CONVERT(VARCHAR(8), dateadd(day,-1, getdate()), 112)
  GROUP BY s.BRANCH, s.CREATEDBYUSER, acct.ACCOUNTNUMBER, s.CLOSEDATE,
     s.CHARGEOFFDATE, s.BALANCE, s.TYPE, s.DESCRIPTION, c.TYPE,
     c.STATUS, c.USAGEDATE, c.CLOSEDATE, c.ISSUEDATE, acct.STATEMENTMAILCODE,
     s.SHARECODE, s.OVERDRAFTTOLERANCE, s.OPENDATE, s.PARENTACCOUNT
  ORDER BY Branch, [Teller Number], [Account Number]
  </code></pre>
  
  <p>Right now I'm getting "1" back for both rows in the Debit column if there are two rows of the same account number. Is there a way for me to get only one "1" if there is more than one entry of the same account number?
  I'm not sure if I need to make this whole query a subquery and create a case outside of that to get only one "1" back in the result.</p>
  
  <p>My Current Result:
  <a href="https://i.stack.imgur.com/3mLzo.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3mLzo.png" alt="My current Result:"></a></p>
  
  <p>My Desired Result:
  <a href="https://i.stack.imgur.com/4BzxH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4BzxH.png" alt="My desired result"></a></p>