SSRS - 根据以 ~ 开头的值从前面的行中添加值



我正在处理一个复杂的场景,我需要显示以前行的美元数量,直到出现波浪号。这是一个例子:

示例图像

根据上面的示例,如果该行以 ~ [波浪号] 开头,则应在"报价零售"字段中显示自己的零售金额。如果该行不以 ~ 开头,则"报价零售"应为空白,但在背景中应为小计,以显示它与 ~ 一起添加波浪线金额。任何意见将不胜感激。

可以在数据库中创建以下存储过程,并在 SSRS 中调用此过程: (注意:我已使用MS SQL Server作为数据库,并在数据库中创建了类似的表,如示例图像所示,除了"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

您可以在 VB 函数(报表的代码部分(中执行此操作,并使用行名和 $ Amount 调用该函数。 添加到总和并返回值以显示它。在第二个函数中,您可以返回总和并将其设置为 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())

最新更新