SSRS-查询​​设计器会自动更改我的查询

时间:2019-06-25 13:28:05

标签: reporting-services

我在SSRS查询设计器中使用AND和OR进行查询,当我执行SQL时,查询更改为完全不同的查询

查询如下所示,最后一个参数SIDSCD可以为空或作为参数输入

     SELECT SCFRAN, SCDPCD, SCMOCD, STMOYR, STCHCD, STMGCD, SCVIN, 
     SCINDT, INVDATE, INVMONTH, INVYEAR, SISMCD, SIDSCD, SIDSC1, SICUNM, 
     SICUCD, SCMGCD, 
                      NSP, WEMEMNL, CDDESL
FROM            VEHICLE.VHVPRICOM2
WHERE        SCFRAN = ? AND STMOYR = ? AND STMGCD = ? AND STCHCD = ? AND SCMOCD = ? AND SISMCD = ? AND (SIDSCD = ? OR ? ='') ```

But the Query designer changes the query to this when i execute SQL


```SELECT        SCFRAN, SCDPCD, SCMOCD, STMOYR, STCHCD, STMGCD, SCVIN, SCINDT, INVDATE, INVMONTH, INVYEAR, SISMCD, SIDSCD, SIDSC1, SICUNM, SICUCD, SCMGCD, 
                      NSP, WEMEMNL, CDDESL
FROM            VEHICLE.VHVPRICOM2
WHERE        (SCFRAN = ?) AND (STMOYR = ?) AND (STMGCD = ?) AND (STCHCD = ?) AND (SCMOCD = ?) AND (SISMCD = ?) AND (SIDSCD = ?) OR
                      (SCFRAN = ?) AND (STMOYR = ?) AND (STMGCD = ?) AND (STCHCD = ?) AND (SCMOCD = ?) AND (SISMCD = ?) AND (? = '')```

1 个答案:

答案 0 :(得分:0)

我找到了解决我提到的问题的另一种方法。它的过程更长一些,但是可以正常工作

1)在“报表数据”中,创建数据源(我正在使用共享数据源)

2)在“报表数据”中,创建一个数据集,然后选择“在报表中使用嵌入式数据集”选项。

3)在写查询的地方,

仅采用选择查询,即“

 SELECT  SCFRAN, SCDPCD, SCMOCD, STMOYR, STCHCD, STMGCD, SCVIN, SCINDT, INVDATE, 
    INVMONTH, INVYEAR, SISMCD, SIDSCD, SIDSC1, SICUNM, SICUCD, SCMGCD, 
                         NSP, WEMEMNL, CDDESL, MMMODS, SCSLTY, SCINPX, SCINNO
FROM            VEHICLE.VHVPRICOM2 ```


Now Click on the button refresh fields ,with this you will get the fields in dataset and you can see them in the fields tab.Otherwise you will have to manually add them in fields tab 

4)
="SELECT        SCFRAN, SCDPCD, SCMOCD, STMOYR, STCHCD, STMGCD, SCVIN, SCINDT, INVDATE, INVMONTH, INVYEAR, SISMCD, SIDSCD, SIDSC1, SICUNM, SICUCD, SCMGCD," & 
"                         NSP, WEMEMNL, CDDESL, MMMODS, SCSLTY, SCINPX, SCINNO FROM VEHICLE.VHVPRICOM2 " &
" WHERE        (SCFRAN = '" & Parameters!PRFranchise.Value & "') AND (STMGCD = '" & Parameters!PRModelGroup.Value & "') AND (SCMOCD = '" & Parameters!PRModelCode.Value & "') AND (SISMCD IN " &
"                             (SELECT        WEMEMCD " &
"                               FROM            VEHICLE.VHTEMPL VHTEMPL_1 " &
"                               WHERE        (WEMEMCD = '" & Parameters!PRSalesManCode.Value & "') OR " &
"                                                         (WEMTLCD = '" & Parameters!PRSalesManCode.Value & "') OR " &
"                                                         (WEMGLCD = '" & Parameters!PRSalesManCode.Value & "') OR " &
"                                                         (WEMBHCD = '" & Parameters!PRSalesManCode.Value & "') OR " &
"                                                         (WEMTCMCD = '" & Parameters!PRSalesManCode.Value & "') OR " &
"                                                         (WEMGCMCD = '" & Parameters!PRSalesManCode.Value & "') OR " &
"                                                         (WEMBCMCD = '" & Parameters!PRSalesManCode.Value & "') OR " &
"                                                         (WEMHOTLCD = '" & Parameters!PRSalesManCode.Value & "') OR " &
"                                                         (WEMHOGLCD = '" & Parameters!PRSalesManCode.Value & "') OR " &
"                                                         (WEMHHODCD = '" & Parameters!PRSalesManCode.Value & "') OR " &
"                                                         (WEMGHODCD = '" & Parameters!PRSalesManCode.Value & "'))) AND (SIDSCD = '" & Parameters!PRDestination.Value & "' OR " &
"                         '" & Parameters!PRDestination.Value & "' ='') AND (CHAR(INVYEAR) = '"& Parameters!PRInvYear.Value &"' OR '"& Parameters!PRInvYear.Value &"' ='') AND (CHAR(STMOYR) = '" & Parameters!PRModelYear.Value &"') AND (STCHCD = '" &Parameters!PRCharCode.Value &"') "

Now click on f(x) and paste your code ,my sample is as above .There are things to be done like first starting letter should be = ,every line must be in " " and ended with &

5) Instead of ? in shared data set ,you can add Parameters in place of the ? like this
'" & Parameters!PRSalesManCode.Value & "'

If we do through f(x) ,the query is not automatically changed and we get our result as we wanted