我可以想到几个选项。在这两种情况下,我都假设了一个包含以下值的参数 SortOrder:
根据参数将排序表达式应用于表
我已将表达式应用于表格的排序:
第一类:
=Switch(Parameters!SortOrder.Value = "CustomerName", Fields!CustomerName.Value
, Parameters!SortOrder.Value = "ZipCode, SIC", Fields!ZIP.Value
, Parameters!SortOrder.Value = "SIC, City", Fields!SIC.Value)
第二种:
=Switch(Parameters!SortOrder.Value = "CustomerName", Fields!CustomerName.Value
, Parameters!SortOrder.Value = "ZipCode, SIC", Fields!SIC.Value
, Parameters!SortOrder.Value = "SIC, City", Fields!City.Value)
在查询中应用排序
您可以order by
根据参数添加到数据集查询以执行相同的操作:
...
order by case @SortOrder when 'CustomerName' then CustomerName
when 'ZipCode, SIC' then ZIP
when 'SIC, City' then SIC
end
, case @SortOrder when 'CustomerName' then CustomerName
when 'ZipCode, SIC' then SIC
when 'SIC, City' then City
end
在这两种情况下,您都会获得基于参数的排序: