title: How to query last 2 business days only
body: <p>I'm running a query that pulls the correct information I'm looking for, but I need it to pull the last 2 business days rather than the last 2 days. This comes into play when it's Monday and my results show information for Monday and Sunday rather than Monday and Friday. How can I change my query to pull in business days only?</p>
  
  <pre><code>USE [LetterGeneration]
  
  SELECT  g.LetterGenerationPrintJobId
        ,CAST(t.[TemplateKey] AS VarChar) AS LetterCode
        ,convert(char(12),r.CreatedDate,101) AS CreatedDate
        ,s.LetterGenerationStatusId AS Status
        ,s.StatusKey AS StatusDesc
        ,count(g.LetterGenerationId) as LetterCount
        ,c.BankingDateYorN
  
    FROM [LetterGenerationTemplateRequest] AS r
  
    INNER JOIN [LetterGenerationTemplate] AS t
    ON t.[LetterGenerationTemplateId] = r.LetterGenerationTemplateId
    INNER JOIN LetterGeneration g
    ON g.LetterGenerationTemplateRequestId = r.LetterGenerationTemplateRequestId
    INNER JOIN LetterGenerationStatus s 
    ON g.LetterGenerationStatusId = s.LetterGenerationStatusId
    INNER JOIN Enterprise..Calendar C
    ON c.BeginDate = g.LetterDate
  
  WHERE ((DATEDIFF(d, r.CreatedDate, GETDATE()) = 0) OR (DATEDIFF(d, r.CreatedDate, GETDATE()) = 1))
  --BankingDateYorN = 1
  --AND RelativeTimeValue_BusinessDates =-1
  AND t.[TemplateKey] NOT LIKE '%PLTV1%' 
  AND s.LetterGenerationStatusId NOT LIKE '4'
  AND s.LetterGenerationStatusId NOT LIKE '16'
  AND s.LetterGenerationStatusId NOT LIKE '19'
  AND s.LetterGenerationStatusId NOT LIKE '20'
  AND s.LetterGenerationStatusId NOT LIKE '38'
  
  
  GROUP BY r.[LetterGenerationTemplateRequestId]
        ,r.LetterGenerationTemplateId
        ,g.Lettergenerationprintjobid
        ,t.[TemplateKey]
        ,r.[Loan_no]
        ,r.CreatedDate
        ,r.[CreatedBy]
        ,s.LetterGenerationStatusId
        ,s.StatusKey
        ,c.BankingDateYorN
  
  
    ORDER BY r.CreatedDate DESC
  </code></pre>
  
  <p><strong>UPDATE: I've recently discovered how to join a calendar table to my current query. The calendar query has a column called BusinessDayYorN with 1's for a business day and 0's for weekends and holidays. I've also updated the old query to now include the join.</strong></p>