在ssrs report builder 2008上选择两个日期作为参数

时间:2013-07-26 14:24:56

标签: sql date parameters period year2038

我需要显示四个参数来显示年份和期间之间的数据,例如我希望返回2011年12期和2012年期间4之间发生的交易

到目前为止,我已经到了但不确定在哪里放我的间隔,我想我还需要< =或> =某处?

SELECT  
    dbo.MBO450.cmpcode AS CMPCODE, 
    dbo.MBO300.yr AS YR, 
    dbo.MBO300.period AS PERIOD, 
    dbo.MBO300.inpdate AS INPUT_DATE, 
    dbo.MBO300.docdate AS DOCUMENT_DATE, 
    dbo.MBO450.doccode AS DOCCODE, 
    dbo.MBO450.docnum AS DOCNUM, 
    dbo.MBO450.el2 AS EL2, 
    dbo.MBO110.vat AS VATCODE, 
    dbo.MBO450.ref1 AS SUPPLIER_INVOICE, 
    dbo.MBO450.ref2 AS INVOICE_REGISTER, 
    dbo.MBO450.ref3 AS EXT_REF3, 
    dbo.MBO450.ref4 AS EXT_REF4, 
    dbo.MBO130.name AS EL2_NAME, 
    MBO450_1.el2 AS SUPPLIER, 
    MBO130_1.name AS [SUPPLIER NAME], 
    dbo.MBO440.vat, 
    dbo.MBO440.federaltax, 
    dbo.MBO440.ten99code, 
    dbo.MBO320.add1, 
    dbo.MBO320.add2, 
    dbo.MBO320.add3, 
    dbo.MBO320.add4, 
    dbo.MBO320.add5, 
    dbo.MBO320.add6, 
    dbo.MBO320.postcode, 
    dbo.MBO320.country, 
    dbo.MBO320.tel, 
    dbo.MBO320.fax, 
    dbo.MBO450.doctaxturn 
FROM 
    dbo.MBO300 
    INNER JOIN dbo.MBO450 
          ON dbo.MBO300.cmpcode = dbo.MBO450.cmpcode 
             AND dbo.MBO300.doccode = dbo.MBO450.doccode 
             AND dbo.MBO300.docnum = dbo.MBO450.docnum 
    INNER JOIN dbo.MBO110 
          ON dbo.MBO450.cmpcode = dbo.MBO110.code 
    INNER JOIN dbo.MBO130 
          ON dbo.MBO450.cmpcode = dbo.MBO130.cmpcode 
             AND dbo.MBO450.el2 = dbo.MBO130.code 
    INNER JOIN dbo.MBO450 AS MBO450_1 
          ON dbo.MBO450.cmpcode = MBO450_1.cmpcode 
             AND dbo.MBO450.doccode = MBO450_1.doccode 
             AND dbo.MBO450.docnum = MBO450_1.docnum 
    INNER JOIN dbo.MBO130 AS MBO130_1 
          ON MBO450_1.el2 = MBO130_1.code 
    INNER JOIN dbo.MBO440 
          ON MBO450_1.el2 = dbo.MBO440.elmcode 
    INNER JOIN dbo.MBO320 
          ON MBO450_1.el2 = dbo.MBO320.elmcode 
WHERE 
    (dbo.MBO450.el2 = 'VIZ') 
    AND (MBO450_1.el2 LIKE 'S%')
    AND dbo.MBO300.yr LIKE (@YEAR) 
    AND dbo.MBO300.period LIKE (@PERIOD) 
ORDER BY 
    YR, PERIOD, DOCNUM

1 个答案:

答案 0 :(得分:0)

将@Year和@Period条件替换为:

(dbo.MBO300.yr > 2011 
    OR (dbo.MBO300.yr = 2011 
        AND dbo.MBO300.period >= 12))
AND (dbo.MBO300.yr < 2012
    OR (dbo.MBO300.yr = 2012 
        AND dbo.MBO300.period <= 4))

或者,使用参数:

(dbo.MBO300.yr > @YEAR_START
    OR (dbo.MBO300.yr = @YEAR_START 
        AND dbo.MBO300.period >= @PERIOD_START))
AND (dbo.MBO300.yr < @YEAR_END
    OR (dbo.MBO300.yr = @YEAR_END
        AND dbo.MBO300.period <= @PERIOD_END))