当我运行加入查询时,结果有限吗?

时间:2015-07-02 06:17:44

标签: sql-server-2008

运行此查询时,我的结果只有5001行

SELECT 
    CASE V_ALL.JOB_qty_BlankPages
        WHEN 0
            THEN V_ALL.JOB_qty_BWPages + V_ALL.JOB_qty_ColorPages + (V_ALL.JOB_qty_BlankPages + ((V_ALL.JOB_qty_SimplexPages + V_ALL.JOB_qty_DuplexPages * 2) - (V_ALL.JOB_qty_BWPages + V_ALL.JOB_qty_ColorPages)))
        ELSE V_ALL.JOB_qty_BWPages + V_ALL.JOB_qty_ColorPages + V_ALL.JOB_qty_BlankPages
    END AS PrintedPages,
    V_ALL.JOB_qty_BWPages AS BWPages,
    V_ALL.JOB_qty_ColorPages AS ColorPages,
    CASE V_ALL.JOB_qty_BlankPages
        WHEN 0
            THEN V_ALL.JOB_qty_BlankPages + ((V_ALL.JOB_qty_SimplexPages + V_ALL.JOB_qty_DuplexPages * 2) - (V_ALL.JOB_qty_BWPages + V_ALL.JOB_qty_ColorPages))
        ELSE V_ALL.JOB_qty_BlankPages
    END AS BlankPages,
    V_ALL.JOB_qty_SimplexPages AS SimplexPages,
    V_ALL.JOB_qty_DuplexPages * 2 AS DuplexPages,
    V_ALL.JOB_qty_SimplexPages + V_ALL.JOB_qty_DuplexPages AS TotalSheets,
    V_All.JOB_lab_NTDomainName,
    V_All.Lab_GroupName,
    V_All.JOB_lab_NTUserName
    ,V_All.Lab_NTFullUserName
    ,V_All.PRINTER_lab_Location
    ,V_All.JOB_lab_DocumentName
    ,V_All.JOB_qty_Size
    ,V_All.JOB_qty_Copies
    ,V_All.JOB_date_Submitted
    ,T_AD_Data.lab_sAMAccountName
    ,T_AD_Data.lab_department
    ,T_AD_Data.lab_physicalDeliveryOfficeName
FROM
    V_All
LEFT JOIN 
    T_AD_Data ON V_ALL.lab_NTFullUserName = T_AD_Data.lab_sAMAccountName
WHERE 
    JOB_date_Submitted BETWEEN '2015-01-01 12:59:59.000'
                       AND '2015-01-31 12:59:59.000';

1 个答案:

答案 0 :(得分:0)

首先检查每个表中有多少行,当你使用左连接时,它将返回左表(V_All)中的所有行,右表中的匹配行(T_AD_Data)。

因此,请检查这些表之间是否存在任何不匹配的行。如果有,则需要更改连接条件。