2013-12-18 40 views
0

進出口工作使用SSRS 2008SQL指望日期

我有一些代碼帶回2列DateAppRcvd和顧問

報告

這裏是我下面的代碼:

SELECT 
     COUNT(pm.DateAppRcvd) AS [DateAppRcvd], 
    u.FullName AS [Advisor] 
FROM tbl_Profile_Mortgage AS pm 
     INNER JOIN tbl_Profile AS p 
      ON pm.FK_ProfileId = p.Id 
     INNER JOIN tbl_User u 
      ON p.Advisor = u.UserId 
WHERE DateAppRcvd Between '01-Nov-2013 00:00:00.000' AND '30-Nov-2013 23:59:00.000' 
AND pm.AccelInd <>'1' 
and u.FullName in ('Colin Sneddon ','Graeme Hastie','Jonathon Bede Pratt','Mark Reidy','Neil Jones','Nigel Crook','Sharon Parouty','Tom McSherry') 
GROUP BY u.FullName 

這會帶給我返回

DateAppRcvd Advisor 
11   Colin Sneddon 
1   Jonathon Bede Pratt 
17   Mark Reidy 
4   Neil Jones 
5   Nigel Crook 
14   Sharon Parouty 
8   Tom McSherry 

怎麼會捨棄格雷姆。我知道爲什麼它這樣做,因爲這個用戶沒有日期/計數。

有沒有一種方法來設置它帶回格雷姆爲0的DateAppRcvd

+0

請給我們一個輸入示例。 – PeterRing

回答

0

假設在格雷姆的情況下,列DateAppRcvd是NULL計數,這應有助於:


SELECT 
    COUNT(pm.DateAppRcvd) AS [DateAppRcvd], 
    u.FullName AS [Advisor] 
FROM 
    tbl_Profile_Mortgage AS pm 
    INNER JOIN tbl_Profile AS p ON pm.FK_ProfileId = p.Id 
    INNER JOIN tbl_User u ON p.Advisor = u.UserId 
WHERE 
    (
     DateAppRcvd Between '01-Nov-2013 00:00:00.000' AND '30-Nov-2013 23:59:00.000' 
     OR 
     DateAppRcvd IS NULL 
    ) 
    AND pm.AccelInd '1' 
    and u.FullName in ('Colin Sneddon ','Graeme Hastie','Jonathon Bede Pratt','Mark Reidy','Neil Jones','Nigel Crook','Sharon Parouty','Tom McSherry') 
GROUP BY u.FullName 
+0

非常感謝您花時間回答我的問題。 – RustyHamster

0

如果Graeme在tbl_Profile_Mortgage中沒有條目,那麼您需要移動連接並使用外部連接(在morgage配置文件和僱員表之間)使空值出現。一旦空值出現,這將導致記錄在聚合函數中計數。

SELECT 
     COUNT(pm.DateAppRcvd) AS [DateAppRcvd], 
    u.FullName AS [Advisor] 
FROM tbl_User u 
     INNER JOIN tbl_Profile AS p 
      ON p.Advisor = u.UserId 
     LEFT OUTER JOIN tbl_Profile_Mortgage AS pm 
      ON pm.FK_ProfileId = p.Id 
WHERE DateAppRcvd Between '01-Nov-2013 00:00:00.000' AND '30-Nov-2013 23:59:00.000' 
AND pm.AccelInd <>'1' 
and u.FullName in ('Colin Sneddon ','Graeme Hastie','Jonathon Bede Pratt','Mark Reidy','Neil Jones','Nigel Crook','Sharon Parouty','Tom McSherry') 
GROUP BY u.FullName