试图结合" OR"和"和" SSRS中的声明

时间:2018-01-04 21:20:05

标签: sql sql-server reporting-services parameters

我在SSRS中合并或/和语句时遇到问题。我使用了几个参数字段,但没有运气。除了开始日期和结束日期之外,我使用数据集中的查询对其他参数进行多选选择。我的问题是获得所有福利,扣除和支付代码,然后将其限制在日期范围内。日期未被过滤。

SELECT
  UPR30100.EMPLOYID
  ,UPR30100.CHEKDATE AS [UPR30100 CHEKDATE]
  ,UPR30100.CHEKNMBR
  ,UPR30100.PYADNMBR
  ,UPR30300.PYRLRTYP
  ,UPR30300.PAYROLCD
  ,UPR30300.CHEKDATE AS [UPR30300 CHEKDATE]
  ,UPR30300.UNTSTOPY
  ,UPR30300.PAYRATE
  ,UPR30300.UPRTRXAM
  ,UPR00100.LASTNAME
  ,UPR00100.FRSTNAME
  ,UPR00100.ADRSCODE
  ,UPR00100.BRTHDATE
  ,UPR00100.SOCSCNUM
  ,UPR00100.STRTDATE
  ,UPR00100.BENADJDATE
  ,UPR00100.LASTDAYWORKED_I
  ,UPR30100.VOIDED
  ,UPR30300.DAYSWRDK
  ,SY01200.INET1
  ,UPR00102.ADDRESS1
  ,UPR00102.ADDRESS2
  ,UPR00102.CITY
  ,UPR00102.[STATE]
  ,UPR00102.ZIPCODE
FROM
  UPR30100
  INNER JOIN UPR30300
    ON UPR30100.CHEKNMBR = UPR30300.CHEKNMBR
  INNER JOIN UPR00100
    ON UPR30100.EMPLOYID = UPR00100.EMPLOYID
  INNER JOIN UPR00102
    ON UPR00100.ADRSCODE = UPR00102.ADRSCODE AND UPR00100.EMPLOYID = UPR00102.EMPLOYID
  INNER JOIN SY01200
    ON UPR00102.EMPLOYID = SY01200.Master_ID AND UPR00102.ADRSCODE = SY01200.ADRSCODE
WHERE UPR30300.PAYROLCD in (@Paycodes)or UPR30300.PAYROLCD in (@Benefits)or UPR30300.PAYROLCD in (@Deductions) and UPR30300.chekdate between (@Begindate) and (@Enddate)

谢谢! 麦克

2 个答案:

答案 0 :(得分:1)

你ORs和INs和AND弄乱了where子句。试试以下。

ys = [{1=>6, 4=>2}, {1=>5}, {4=>1}]
group_values(ys) # => {1=>[6, 5], 4=>[2, 1]}

答案 1 :(得分:0)

将三个内容合并为

中的一个

UPR30300.PAYROLCD(@Paycodes,@ Benefits,@ Deductions)和UPR30300.chekdate(@Begindate)和(@Enddate)之间

或使用括号内的括号

WHERE(@Paycodes中的UPR30300.PAYROLCD或(@Benefits)中的UPR30300.PAYROLCD或(@Deductions)中的UPR30300.PAYROLCD)和(@Begindate)和(@Enddate)之间的UPR30300.chekdate