SSRS - 根据以 ~ 开头的值添加前几行的值

SSRS - Add a value from previous rows based on value which start with ~

我正在处理一个复杂的场景,在该场景中,我需要显示之前几行的金额,直到出现波浪号。这是一个例子:

example image

根据上面的示例,如果该行以 ~ [波浪号] 开头,它应该在 'Retail on quote' 字段中显示自己的零售金额。如果该行不是以 ~ 开头,那么 'Retail on quote' 应该是空白的,但在背景中显示小计以显示它与 ~ 添加波浪线数量以及。任何输入将不胜感激。

您可以在 VB 函数(报告的代码部分)中执行此操作,并使用行名和 $ Amount 调用该函数。 添加到总和和 return 值以显示它。在第二个函数中,您可以 return 总和并将其设置为 0。

不确定这是否全部正确VB,但它看起来像这样:

Public Function SumUp(line As String, value As Double) As Double
        sum = sum + value
        Return value
End Function

Public Function GetSum() As Double
        Dim v = sum
        sum = 0
        Return sum
End Function

在您的值字段中调用如下函数:

=Code!SumUp(Fields!Line, Fields!Value)

在您的 Sum-Field 中调用 IIF 表达式中的 GetSum 函数,例如

=IIF(pseudo:Fields starts with~, "", Code!GetSum())

您可以在数据库中创建以下存储过程,并在 SSRS 中调用该过程: (注意:我使用 MS SQL 服务器作为数据库并在数据库中创建了类似的 table,如您在示例图像中所示,列 "Retail_On_QUOTE" 除外)

create or alter procedure test_sproc 
as
begin
create table #tbl1 (col1 char(10), Retail int, Retail_On_QUOTE int)
insert into #tbl1 select Col1, retail, 0 from tbl1
declare c1 cursor for select Col1, retail from #tbl1
declare @total int=0, @col1 char(10), @retail int, @total2 int=0
open c1
fetch next from c1 into @col1, @retail
WHILE @@FETCH_STATUS = 0 
begin
    if  left(@col1,1) = '~' 
        begin

            set @total = @retail+@total2
            set @total2 = 0
        end
    else
        begin
            set @total2 = @total2+@retail
            set @total = 0
        end
    print @total
    update #tbl1 set Retail_On_QUOTE = @total where col1 = @col1
    fetch next from c1 into @col1, @retail
end
close c1
deallocate c1
select col1, Retail, Retail_On_QUOTE from #tbl1
end