1

我有一个非常简单的 SQL 查询

Select distinct title from agents 
 where 
title like '%Engineer%'

this renders a few results back, what I am looking to do is some how only SHOW the top 1 result to the users of there SRSS report as this will be a variable selection, but when selecting this single record it will include all of other results在搜索中。

所以基本上所有结果都将对最终用户隐藏,但他们实际上正在做的是选择从上述查询返回的所有结果。

这可能吗?

4

1 回答 1

0

我会为报告参数设置一个默认值并创建一个类似这样的存储过程

CREATE Proc usp_ReportProc
@Title NVARCHAR(30) = 'SomeDefaultValue'
AS
BEGIN
  SET NOCOUNT ON;

  IF @Title = 'SomeDefaultValue'
    BEGIN
        Select Top 1 title from agents 
     where title like '%Engineer%'
  END 
  ELSE 
   BEGIN
    Select distinct title from agents 
    where title IN (@Title)
  END 
END

从您的报告中调用此存储过程,当报告最初运行时,它将传递您在报告参数中设置的“SomeDefaultValue”,并将返回 TOP 1 行,但当用户传递任何不同的值时,它将相应地显示结果。当用户传递参数时,您可以进一步调整查询以使用 LIKE 运算符。

于 2013-11-04T22:12:35.460 回答