重写 SQL Server 2008 Report Builder 3.0 中的排序?
我在 Report Builder 3.0 中使用 SQL 查询创建了一个数据集。我没有在查询中指定 order by
,而是使用 union all
按我想要的顺序堆叠结果。该数据集中的第一列称为Product
。
当我在报表生成器中创建表并引用 Product
列时,它出于某种原因希望默认对此列按字母顺序排序 - 这是我不希望的。
我能做些什么?? Report Builder 3.0 看起来相当原始,所以如果我对这种烦恼无能为力,那就这样吧。
I created a dataset with a SQL query in Report Builder 3.0. I did NOT specify an order by
in the query, but instead used union all
to stack the results in the order I wanted. The first column in this dataset is called Product
.
When I create a table in Report Builder, referencing the Product
column, it for whatever reason wants to default to alphabetical sorting of this column - which I do not want.
What can I do?? Report Builder 3.0 seems pretty primitive, so if there isn't anything I can do about this annoyance than so be it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
@Catcall 关于结果集“未定义”的说法绝对正确。不过,我认为您看到按第一列排序的结果的原因可能是因为您使用了报表生成器向导来创建输出表。这往往会创建一堆嵌套的行组,并且可能首先对产品进行分组,从而对产品进行排序。
如果您创建一个新表并将该行保留为“详细信息”行(它将显示为等号而不是括号/大括号),那么通常报表生成器将按照查询返回的顺序输出。
然而,最佳实践是显式定义排序顺序,我会在每个查询中使用 RANK() 或类似的方法来为您提供数字排序顺序列。然后在报表生成器中使用它作为排序表达式。
@Catcall is absolutely right regarding the resultset being 'undefined'. However I think the reason you are seeing the results sorted by the first column is probably because you've used the Report Builder wizard to create the output table. This tends to create a bunch of nested row groups and is probably grouping first on product and thus sorting on product.
If you create a new table and leave the row as 'details' rows (it will show as an equals sign rather than a bracket / brace) then generally Report Builder will output in the order returned by the query.
HOWEVER, it is best practice to explicitly define the sortorder, I would use
RANK()
or similar within each query to give you a numericSortOrder
column. Then use this within Report Builder as the Sort expression.尝试删除行组中的排序选项。 (组属性/排序)。
接下来,在 tablix 属性中添加新的排序。
https://msdn.microsoft.com/en-us/library/dd255193.aspx
Try to remove the sorting options in Row Groups. (Group properties / Sorting).
Next, add a new sorting in the tablix properties.
https://msdn.microsoft.com/en-us/library/dd255193.aspx
如果没有显式的
ORDER BY
子句,则返回的订单行是不确定的。随着执行环境的变化,它可以而且经常从一次运行更改为另一次运行。如果您不指定ORDER BY
,查询优化器可以按照它认为最有效的顺序返回行。你不能指望它每次都做出相同的选择。也许报表生成器将在基础查询中遵循显式的
ORDER BY
。In the absence of an explicit
ORDER BY
clause, the order rows will be returned is indeterminate. It can--and often does--change from one run to another as the execution environment changes. If you don't specify anORDER BY
, the query optimizer is free to return rows in the order it decides is most efficient. You can't rely on it to make the same choices every time.Perhaps Report Builder will honor an explicit
ORDER BY
in the underlying query.