如何實現兩個參數,每個參數都是可選的,每個參數的可用值?

[英]How to implement two parameters that are each optional with available values for each parameter?


Two parameters that allow user to choose either one to sort data.

兩個參數,允許用戶選擇其中一個來排序數據。

SELECT comment, comment_type,user
FROM comments
WHERE (comments.comment_type = @ctype) OR (comments.user = @user)

The user must be able to select each commenttype or user from available values dropdown. The problem is ssrs will not let me leave one blank. I tried using IN but it errored out.

用戶必須能夠從可用值下拉列表中選擇每個評論類型或用戶。問題是ssrs不會讓我留下一個空白。我嘗試使用IN但它出錯了。

3 个解决方案

#1


3  

How about

(comments.comment_type = @ctype AND comments.user IS NOT NULL) OR 
(comments.comment_type IS NOT NULL AND comments.user = @user)

#2


0  

You should check Allow null value in Report parameters window.

您應該在“報告參數”窗口中選中“允許空值”。

Than you can try your query or below query.

您可以嘗試查詢或以下查詢。

SELECT comment, comment_type,user
FROM comments
WHERE (comments.comment_type = coalesce(@ctype,comments.comment_type)) OR (comments.user = coalesce(@user,comments.user))

More information

#3


0  

Try this:

CREATE PROC myproc (
@ctype varchar(10) = null,
@user varchar(10) = null
) as 
BEGIN

  SELECT comment, comment_type,user
  FROM comments
  WHERE (comments.comment_type = ISNULL(@ctype, comments.comment_type))
  OR (comments.user = ISNULL(@user,comments.user))

END

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2013/09/10/251ea31c6d5931fefb78e6c2c88eaf44.html



 
粤ICP备14056181号  © 2014-2021 ITdaan.com