3

我正在为 SSRS 中的 SSMS 2008 R2 报告参数开发一个存储过程。我目前正在使用此脚本填充此参数:

Select
    Null As [program_id],
    '-All-' As [program_name]
UNION ALL
SELECT DISTINCT
    [program_info_id] AS [program_id],
    [program_name]
FROM [evolv_reports].[dbo].[programs_view]
Order By [program_name]

但问题是现在有一个名为“(MS) Family Preservation Services”的新程序名称。该程序列在“-All-”之前,因此现在此报告参数不再默认为“-All-”。如何使“-All-”再次列为第一?这是我当前参数输出的一部分:

program_id  program_name
406B3C38-D8D3-4ED5-AC5B-9013D3662931    (MS) Family Preservation Services
NULL                                    -All-
F6E2C172-2BFB-45BC-B870-E7BC2414DD91    Adoptions - Agency
C766E084-AB03-41AD-92B9-494FF3975E10    Adoptions - Subcontract
C21DACE0-8F34-433D-BE24-A79DE322F7EF    AL Step down foster care
4

2 回答 2

2
SELECT [program_id], [program_name] FROM 
(
   Select 
  Null As [program_id], 
  '-All-' As [program_name] ,
  0 as num1
  UNION ALL 
 SELECT DISTINCT 
  [program_info_id] AS [program_id], 
  [program_name] ,
  1 as num1
)a
ORDER BY a.num1, a.[program_name] -- or just by a.num1 if you don't need to sort by program_name
于 2012-04-20T14:35:56.337 回答
0

也许是这样的:

SELECT
    *
FROM
(
Select
    Null As [program_id],
    '-All-' As [program_name]
UNION ALL
SELECT DISTINCT
    [program_info_id] AS [program_id],
    [program_name]
FROM [evolv_reports].[dbo].[programs_view]
) AS T
Order By (CASE WHEN [program_id] IS NULL THEN 0 ELSE 1 END), [program_id]
于 2012-04-20T14:41:37.353 回答