Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You need to use a Left Join from Contacts to Tasks (i.e., show all contacts and any matching Tasks). In addition, you need to move the criteria <code>t.TaskType &lt;&gt; '[=] Auto Email'</code> to the ON clause or change the Where clause filter to be:</p> <p>(<code>t.TaskType &lt;&gt; '[=] Auto Email' Or t.TaskType Is Null)</code>. </p> <p>Otherwise, your Left Join to Tasks will effectively become an Inner Join.</p> <pre><code>SELECT c.MarketSource AS [Market Source] , Coalesce(u.FirstName + ' ', ' ') + Coalesce(u.LastName, ' ') AS [Producer] , Coalesce(c.FirstName + ' ', ' ') + Coalesce(c.MiddleName + ' ', ' ') + Coalesce(c.LastName, ' ') AS [Lead Name] , t.TaskType AS [Task], Coalesce (t.workflow_resultchosen_label, t.result, ' ') AS [Task Result] , Dateadd(HOUR, @utcoffset, c.createdon) AS [Received On] , Dateadd(HOUR, @utcoffset, ( MIN (t.completed) )) AS [Completed] , (SELECT COUNT() FROM Quotes q WITH (NOLOCK) WHERE SaleID IS NULL AND c.ContactID = q.ContactID) AS [Pending Quotes] , (SELECT COUNT() FROM Sales s WITH (NOLOCK) WHERE s.Client_ID = c.ContactID) AS [Total Sales] From Contacts As C WITH (NOLOCK) Left Join Tasks t WITH (NOLOCK) On t.TargetID = C.ContactId And t.TaskType &lt;&gt; '[=] Auto Email' LEFT JOIN Users U WITH (NOLOCK) ON u.UserID = t.UserID WHERE iLeadPartnerID IS NOT NULL AND ( c.CreatedOn BETWEEN @startDate AND @endDate ) AND MarketSource IS NOT NULL AND c.WorkgroupId = @workgroupID AND Len(c.MarketSource) &gt; 0 GROUP BY c.MarketSource, u.LastName, u.FirstName, c.ContactId , c.LastName, c.FirstName, c.MiddleName, c.CreatedOn, t.TaskType , t.Result, t.Workflow_ResultChosen_Label ORDER BY c.LastName, c.MiddleName, c.FirstName </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload