1

我有一份报告需要在文本字段参数中接受数字范围和逗号分隔值。该参数用于“帐户类型”,他们希望能够输入“1,2,5-9”,这将采用整数值 1,2,5,6,7,8,9。我知道如何使用单个值来执行此操作,但从不使用范围。

我将用于单个值的示例代码是:

    SELECT
      arcu.vwARCUAccount.AccountType
      ,arcu.vwARCUAccount.ACCOUNTNUMBER
    FROM
      arcu.vwARCUAccount
    WHERE
      arcu.vwARCUAccount.AccountType = @AccountType

任何信息都会非常有帮助。我团队中的某个人已经估计了它,并说它可以在没有意识到他们想要一个范围的情况下完成,所以现在我被困住了。我敢打赌这里的每个人都在我的位置上,所以我提前感谢大家。

4

3 回答 3

1

你想做几件事。

A. 设置一个数据类型为“整数”的参数,并确保选中“允许多个值”复选框。将其值设置为“整数”。暂时打好。

这实际上设置了一个数据集的数组可用列表,您为该类型的数据类型定义可以传递多个数据集。

B. 创建一个名为“values”的简单数据集,如下所示

    declare @Ints table ( id int);

    insert into @Ints values (1),(2),(5),(6),(7),(8),(9)

C. 回到第一步中的变量并打开它的属性。在侧窗格中选择“可用值”。选择单选按钮“从查询中获取值”。将您的数据集列为“值”,将您的值和标签列为“id”。

您现在已将参数数组绑定到您指定的值。然而,用户不必只选择其中一项或全部,而是选择其中一项或多项。

D. 你需要设置你的主数据集(我假设你在来这里之前已经这样做了)。出于我的示例的目的,我将制作一个简单的示例。我创建了一个名为 person 的数据集:

    declare @Table Table ( personID int identity, person varchar(8));

    insert into @Table values ('Brett'),('Brett'),('Brett'),('John'),('John'),('Peter');

    Select *
    from @Table
    where PersonID in (@Ints)

重要的部分是谓词显示:

'PersonID in (@Ints)'

这告诉数据集,它依赖于用户在此数组参数中选择一个值。

于 2013-01-08T20:43:31.427 回答
0

我对 tsql 并不完全精通,但是使用 reg 表达式呢?

请参阅LIKE (Transact-SQL)

如:

arcu.vwARCUAccount.AccountType like '[' + replace(@AccountType, ',','') + ']'
于 2013-01-08T10:04:33.350 回答
0

这可以工作。作为一个粗略的刷子尝试:

  1. 从 tsql 中删除帐户类型的过滤器。

  2. 创建一个输入数字的 vb 函数,这是帐户类型,并测试它是否在用户提供的参数字符串中并输出 1 或 0。vb 函数

    Function test(byval myin as integer, byval mylimits as string) as integer
    'results as 1 or 0

      dim mysplit as string()= Split(mylimits, ",")
      dim mysplit2 as string(1)

      'look through all separated by a ","
      For Each s As String In mysplit 

        'does there exists a range, i.e. "-"? 
        if s like "%-%" then
          mysplit2 = split(s, "-")

          'is the value between this range?
          if myin >= mysplit(0) andalso myin <= mysplit(1) then 
            return 1
          end if

        'is the value equal to the number?
        elseif s = myin then
          return 1

        end if
      Next s

      return 0

    End

3. 使用 vb 函数在数据集上创建一个过滤器,账户类型作为输入等于 1。

    =code.test(Fields!AccountType.Value, Paramaters!MyPar.Value)
于 2013-01-09T08:33:50.807 回答