什么可能导致下拉列表(选择)忽略其值字段?

发布于 2024-11-28 21:00:56 字数 576 浏览 1 评论 0原文

我有一个包含多个参数的报告,其中有 CompanyID。可用值来自值字段设置为“值”且标签字段设置为“标签”的数据集。不完全是火箭科学。查询看起来像这样:

select null as Value, ' Any' as Label
union all
select CompanyID as Value, CompanyName as Label from core.Companies
order by Label

好的,没什么意外。当我运行该查询时,我得到类似

1506 Amalgamated Steel 
2341 Beson Industries
245  Carver Holdings 
etc....

看起来不错的信息。但是,当我查看报表查看器中生成的 HTML 时,生成的 select 元素已为值排序整数:1、2、3、4 等,因此不能按公司 ID 过滤结果在职的。

什么可能导致这种情况?查询返回正确的值,值正在填充到下拉列表中,参数的值字段设置为查询中的值字段。 他们只是在选择/选项字段中没有正确的值。

I've got a report that has several parameters, among them CompanyID. The available values come from a dataset with the Value field set to "Value" and the Label field set to "Label". Not exactly Rocket Science. The query looks like this:

select null as Value, ' Any' as Label
union all
select CompanyID as Value, CompanyName as Label from core.Companies
order by Label

Ok, no surprises. When I run that query I get things like

1506 Amalgamated Steel 
2341 Beson Industries
245  Carver Holdings 
etc....

Looks fine. However, when I view the HTML generated in report viewer, the select element that is generated has ordered integers for values: 1,2,3,4 etc. so filtering the results by company ID isn't working.

What could cause this? The query is returning the correct values, the values are being populated in the dropdown, the Value field for the param is set to the Value field from the query. They just don't have the correct value in the select/option field.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

温柔嚣张 2024-12-05 21:00:56

我无法在报告服务中重现这一点,它对我来说工作得很好。
我的查询是类似的,尽管我总是希望您提到的值“全部”或“任何”位于我的列表的顶部,这样用户就不必寻找它。我也不包含 null 作为值,我将 null 转换为值 0:

SELECT
       1 As SortOrder,
       CompanyID as Value,
       Company as Label
FROM
       Core.Companies
UNION ALL
SELECT
       0 as SortOrder,
       0 as Value,
       "All" as Label
ORDER BY 
        'bring all / any to the top
        'then order the rest by company name
        SortOrder, 
        Label        

这确保 null 不包含在结果列表中...然后在我的主查询中,当我想要过滤时,提取数据的查询公司 ID 或我所做的一切:

SELECT
      ...
FROM
      Mytable
WHERE
      CompanyID = @CompanyID OR @CompanyID = 0    'handle one customer or all customers

报告工作正常,我的选择具有正确的值...

I cannot reproduce this in reporting services, it is working exactly fine for me.
My query is similiar although I always want the value "All" or "Any" as you mentioned to be at the top of my list so users dont have to look for it. I also do not include null as a value, I translate null to the value 0:

SELECT
       1 As SortOrder,
       CompanyID as Value,
       Company as Label
FROM
       Core.Companies
UNION ALL
SELECT
       0 as SortOrder,
       0 as Value,
       "All" as Label
ORDER BY 
        'bring all / any to the top
        'then order the rest by company name
        SortOrder, 
        Label        

This ensures the null is not included in the result list...then in my main query the query that pulls the data, when I want to filter for the company id or all I do this:

SELECT
      ...
FROM
      Mytable
WHERE
      CompanyID = @CompanyID OR @CompanyID = 0    'handle one customer or all customers

The report works fine and my select has the correct values...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文