SSRS在两个日期之间过滤?

时间:2017-05-24 14:57:09

标签: sql reporting-services ssrs-2008 ssrs-2012

在2017-05-18和2017-05-18之间创建现有数据,当我在CRM中使用这些日期运行我的报告时,#34;来自" " To",它不会返回任何数据。接下来在Microsoft SQL Server Management Studio中,当我使用上述日期运行查询时,它仍然不会返回数据,但是当我向查询添加时间时,它会返回介于' 2017-05-18 00:00之间的所有现有数据:00.000'和' 2017-05-18 23:59:59.000'

我如何在SSRS中进行此操作,以便从相同的"从日期"返回数据。和#34; To"日期? SSRS在两个日期之间过滤?

SELECT        
    Account.mm_registrationnumber AS CL_Reg_Number, 
    Account.Name, 
    Account.mm_supplierstatus AS Supplier_Status, 
    Account.PrimaryContactIdName AS Primary_Contact, 
    Account.EMailAddress1 AS Email, 
    Account.Telephone1 AS Telephone, 
    mm_address.mm_line1 AS Line1, 
    mm_address.mm_line2 AS Line2, 
    mm_address.mm_line3 AS Line3, 
    mm_address.mm_line4 AS Line4, 
    mm_address.mm_city AS City, 
    mm_address.mm_county AS County, 
    mm_address.mm_postcode AS Postcode, 
    mm_turnover.mm_name AS Signup_Turnover, 
    Account.mm_signupdate AS SignUp_Date, 
    mm_payment.mm_paymenttype AS Payment_Type, 
    mm_payment.mm_paymentstatus AS Payment_Status, 
    mm_payment.mm_vatamount AS Payment_Amount_VAT, 
    mm_payment.mm_paymentamount AS Payment_Amount_Net, 
    Invoice.InvoiceNumber AS Invoice_ID, 
    Invoice.DueDate AS Due_Date, 
    Invoice.CreatedOn AS Created_Date

FROM  Account 
    INNER JOIN mm_payment ON mm_payment.mm_organisation = Account.AccountId 
    INNER JOIN mm_address ON Account.mm_address = mm_address.mm_addressId 
    INNER JOIN mm_turnover ON Account.mm_turnover = mm_turnover.mm_turnoverId 
    INNER JOIN Invoice ON Invoice.AccountId = Account.AccountId

WHERE Invoice.CreatedOn between '2017-05-18 00:00:00.000' and '2017-05-18 23:59:59.000'

2 个答案:

答案 0 :(得分:0)

将您的CreatedOn列投射为如下日期:

WHERE CAST(Invoice.CreatedOn AS DATE) BETWEEN '2017-05-18' AND '2017-05-18'

答案 1 :(得分:0)

如果您不需要使用时间,请使用强制转换将 DATETIME 字段转换为 DATE 字段,它将提取该日期的所有记录。

WHERE Cast(Invoice.CreatedOn as DATE)  between '2017-05-18' and '2017-05-18'

如果确实需要时间,请将日期/时间参数默认为

=NOW()

,它将在参数中显示时间。Time