Making a filter parameter optional

血红的双手。 提交于 2019-12-13 20:04:15

问题


I am using SSRS 2005. I created a report parameter named icVar. What should i do to allow this filter to be optional. Meaning if user enter something into the textbox, will display result according to what is entered but if nothing is entered it will just treat it to display all. This is the query in my dataset.

SELECT PASS_M, ENTRY_DT, EXIT_DT, WORKED_HRS, ACCESS_LOCATION_X, IC_N, COMPANY_M,  
CONSECUTIVE_D
FROM TEMP_TARGET
WHERE (CONSECUTIVE_D >= @consecDays) AND (ENTRY_DT BETWEEN @startDate AND @endDate) AND
(ACCESS_LOCATION_X LIKE @accessVar) AND
(IC_N LIKE @icVAr) 

I am making use of the wildcard % for my icVar. So if user input S123 for that filter the report will display result where IC_N values starting with S123... However when nothing is entered for that filter, do not force the user to input anything. It shall show IC_N Like %(means all) if nothing is entered.

Any help is appreciated. Thanks.


回答1:


Just use expression evaluation short-circuiting - test for Null first and only if it is not Null does the next part of the expression evaluate, testing for LIKE (see the condition on the last line):

SELECT PASS_M, ENTRY_DT, EXIT_DT, WORKED_HRS, ACCESS_LOCATION_X, IC_N, COMPANY_M, CONSECUTIVE_D
FROM TEMP_TARGET
WHERE (CONSECUTIVE_D >= @consecDays) 
AND (ENTRY_DT BETWEEN @startDate AND @endDate) 
AND (ACCESS_LOCATION_X LIKE @accessVar) 
AND ((@icVar IS NULL) OR (IC_N LIKE @icVAr))


来源:https://stackoverflow.com/questions/13871372/making-a-filter-parameter-optional

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!