我有一个报告,它需要接受文本字段参数中的数字范围和逗号分隔值。该参数用于“帐户类型”,他们希望能够输入"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任何信息都会非常有帮助。我的团队中有人已经估计了它,并说它甚至可以在没有意识到他们想要一个范围的情况下完成,所以现在我被困住了。我打赌在座的每一个人都处在我的位置上,所以我要提前感谢大家。
发布于 2013-01-09 04:43:31
有几件事你想做。
A.设置一个数据类型为'integer‘的参数,并确保选中了'Allow multiple values’复选框。将它的值设置为“Ints”。现在点击now。
这实际上设置了您为该类型的数据类型定义的数据集的数组可用列表,该数据类型可以传递多个数据集。
B.创建一个名为'values‘的简单数据集,如下所示
declare @Ints table ( id int);
insert into @Ints values (1),(2),(5),(6),(7),(8),(9)C.回到第一步中的变量,打开它的属性。在侧窗格中选择“可用值”。选择单选按钮“从查询中获取值”。将您的数据集列为'values‘,将您的值和标签列为'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)重要的部分是谓词,它显示:
‘'where in (@Ints)’
这将告诉数据集,它依赖于用户在此数组参数中选择一个值。
发布于 2013-01-08 18:04:33
我并不完全精通tsql,但是如何使用reg表达式呢?
请参阅LIKE (Transact-SQL)
例如:
arcu.vwARCUAccount.AccountType like '[' + replace(@AccountType, ',','') + ']'发布于 2013-01-09 16:33:51
这可能行得通。作为broud笔刷尝试:
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 =code.test(Fields!AccountType.Value, Paramaters!MyPar.Value)https://stackoverflow.com/questions/14206569
复制相似问题