根据委托日期从报告中删除行

时间:2019-02-06 15:17:45

标签: sql reporting-services

我需要根据委托日期完成情况从报告中删除行(未显示)。

SELECT  
        proj.ProjectNumber AS [Project],
        proj.UserText4 AS [Sales Rep],
        bc.Name AS [Customer Name],
        proj.Address3 AS [Shiped to], 
        proj.City,
        proj.State,
        v_InvDet.InvoiceNumber AS [Invoice],

        CASE WHEN CAST(v_InvDet.InvoiceDate  as Date) = '01/01/1900' 
        then NULL else convert(varchar(10), v_InvDet.InvoiceDate, 101) 
        END AS [Invoice Date], 

        CASE WHEN CAST(proj.UserDate4  as Date) ='01/01/1900' 
        then NULL else convert(varchar(10), proj.UserDate4, 101) 
        END AS [Install Date],

        --CASE WHEN CONVERT(DATE, proj.UserDate4) = '1900-01-01'
        --THEN NULL
        --ELSE CONVERT(CHAR(10), proj.UserDate4, 120)
        --+ ' ' + CONVERT(CHAR(8), proj.UserDate4, 108)
        --END AS [Install Date],

        --case WHEN CONVERT(CHAR(10), proj.UserDate4, 120) > DATEADD( d, -30, GETDATE() )
        --THEN proj.UserDate4
        --END  AS [Install Date],

        case WHEN CONVERT(DATE, proj.UserDate4) = '1900-01-01'
        THEN NULL
        ELSE DATEDIFF(d, CURRENT_TIMESTAMP, proj.UserDate4)*-1
        END  AS [Open Days],

        IIF(proj.UserText9  = 'TRUE', 'YES', 'NO') AS [HVLS Fans],
        IIF(proj.UserText18  = 'TRUE', 'YES', 'NO') AS [Restrains],
        IIF(proj.UserText23  = 'TRUE', 'YES', 'NO') AS [Docks],
        IIF(proj.SitePM  = 'TRUE', 'YES', 'NO') AS [Doors],
        IIF(proj.ProjectURL  = 'TRUE', 'YES', 'NO') AS [Lifts],

        proj.UserText2 AS [Commission Equip], 

        CASE WHEN CAST(proj.Userdate5 as Date)  > DATEADD( d, -14, GETDATE() ) 
        then NULL 
        else convert(varchar(10), proj.Userdate5, 101) 
        END AS [Commission Date2],

    /* Converting 01/01/1900 to NULL so it will show no date on report*/
        CASE WHEN CAST(proj.Userdate5 as Date) = '01/01/1900' then NULL else convert(varchar(10), proj.Userdate5, 101) 
        END AS [Commission Date],

        --case WHEN CAST(proj.Userdate5 as Date) = '01/01/1900' > DATEADD( d, -14, GETDATE() )
        --THEN proj.UserDate5
        --END  AS [Commission Date1],
        --proj.Userdate5 = DATEADD(d, 14, CURRENT_TIMESTAMP ),
        --proj.Userdate5 as [Commission Date],
        proj.UserText3 AS [Commission By]


FROM Project proj

LEFT JOIN v_InvoiceDetail As v_InvDet (nolock) ON proj.ProjectNumber = v_InvDet.ProjectNumber
LEFT JOIN Company AS bc (nolock) ON bc.CompanyID = proj.BillingCompanyID
WHERE
proj.Userdate5 >= DATEADD(d, -14, CURRENT_TIMESTAMP)
 --proj.Userdate5 >= DATEADD(d, -14, CONVERT(datetime,(convert(varchar(12),proj.Userdate5, 101)))) --getdate())-14
--proj.Userdate4 between '2018-01-01' and CURRENT_TIMESTAMP 

--v_InvDet.InvoiceDate between '2018-01-01' and CURRENT_TIMESTAMP 
--v_InvDet.InvoiceDate >= DATEDIFF(d, proj.UserDate4, getdate())
--v_InvDet.InvoiceDate >= DATEADD( d, -140, GETDATE() )

ORDER BY proj.UserText4

我在过滤器附近使用了“ where”。这是做到这一点的方法吗?谢谢

1 个答案:

答案 0 :(得分:0)

只需将您的查询与另一个查询一起包装,以便您的实际查询将是内部查询,然后放入您的条件。

查看此内容:

select * from (
    SELECT  
        proj.ProjectNumber AS [Project],
        proj.UserText4 AS [Sales Rep],
        bc.Name AS [Customer Name],
        proj.Address3 AS [Shiped to], 
        proj.City,
        proj.State,
        v_InvDet.InvoiceNumber AS [Invoice],

        CASE WHEN CAST(v_InvDet.InvoiceDate  as Date) = '01/01/1900' 
        then NULL else convert(varchar(10), v_InvDet.InvoiceDate, 101) 
        END AS [Invoice Date], 

        CASE WHEN CAST(proj.UserDate4  as Date) ='01/01/1900' 
        then NULL else convert(varchar(10), proj.UserDate4, 101) 
        END AS [Install Date],

        --CASE WHEN CONVERT(DATE, proj.UserDate4) = '1900-01-01'
        --THEN NULL
        --ELSE CONVERT(CHAR(10), proj.UserDate4, 120)
        --+ ' ' + CONVERT(CHAR(8), proj.UserDate4, 108)
        --END AS [Install Date],

        --case WHEN CONVERT(CHAR(10), proj.UserDate4, 120) > DATEADD( d, -30, GETDATE() )
        --THEN proj.UserDate4
        --END  AS [Install Date],

        case WHEN CONVERT(DATE, proj.UserDate4) = '1900-01-01'
        THEN NULL
        ELSE DATEDIFF(d, CURRENT_TIMESTAMP, proj.UserDate4)*-1
        END  AS [Open Days],

        IIF(proj.UserText9  = 'TRUE', 'YES', 'NO') AS [HVLS Fans],
        IIF(proj.UserText18  = 'TRUE', 'YES', 'NO') AS [Restrains],
        IIF(proj.UserText23  = 'TRUE', 'YES', 'NO') AS [Docks],
        IIF(proj.SitePM  = 'TRUE', 'YES', 'NO') AS [Doors],
        IIF(proj.ProjectURL  = 'TRUE', 'YES', 'NO') AS [Lifts],

        proj.UserText2 AS [Commission Equip], 

        CASE WHEN CAST(proj.Userdate5 as Date)  > DATEADD( d, -14, GETDATE() ) 
        then NULL 
        else convert(varchar(10), proj.Userdate5, 101) 
        END AS [Commission Date2],

    /* Converting 01/01/1900 to NULL so it will show no date on report*/
        CASE WHEN CAST(proj.Userdate5 as Date) = '01/01/1900' then NULL else convert(varchar(10), proj.Userdate5, 101) 
        END AS [Commission Date],

        --case WHEN CAST(proj.Userdate5 as Date) = '01/01/1900' > DATEADD( d, -14, GETDATE() )
        --THEN proj.UserDate5
        --END  AS [Commission Date1],
        --proj.Userdate5 = DATEADD(d, 14, CURRENT_TIMESTAMP ),
        --proj.Userdate5 as [Commission Date],
        proj.UserText3 AS [Commission By]


FROM Project proj

LEFT JOIN v_InvoiceDetail As v_InvDet (nolock) ON proj.ProjectNumber = v_InvDet.ProjectNumber
LEFT JOIN Company AS bc (nolock) ON bc.CompanyID = proj.BillingCompanyID
WHERE
proj.Userdate5 >= DATEADD(d, -14, CURRENT_TIMESTAMP)
 --proj.Userdate5 >= DATEADD(d, -14, CONVERT(datetime,(convert(varchar(12),proj.Userdate5, 101)))) --getdate())-14
--proj.Userdate4 between '2018-01-01' and CURRENT_TIMESTAMP 

--v_InvDet.InvoiceDate between '2018-01-01' and CURRENT_TIMESTAMP 
--v_InvDet.InvoiceDate >= DATEDIFF(d, proj.UserDate4, getdate())
--v_InvDet.InvoiceDate >= DATEADD( d, -140, GETDATE() )
)
where [Commission Date] not in ( ....) 
ORDER BY proj.UserText4