如何在 SSRS 表达式中编写此 Crystal 报表公式?

How to Write this Crystal Report formula in SSRS Expression?

我在转换此 Crystal SSRS 表达式中的报告公式时遇到问题 谁能帮助我?

公式 1:

Dim fromExDay as String
Dim toExDay as String
Dim sYr as String
Dim sMonth as String
Dim sDay as String

fromExDay = ToText({wk_TORIO0460_a.HktrExchngDayFrom})
fromExDay = Replace (fromExDay, ",", "" )
fromExDay = Replace (fromExDay, ".", "" )

toExDay = ToText({wk_TORIO0460_a.HktrExchngDayTo})
toExDay = Replace (toExDay, ",", "" )
toExDay = Replace (toExDay, ".", "" )
if Len (Trim(fromExDay)) > 0 and Len (Trim(toExDay)) > 0 then
    sYr = Right(Left(fromExDay, 4),2)
    if sYr <> "99" then
        sYr = LEFT(CStr(CDbl(sYr) + 12),2)
    end if
    sMonth = Mid(fromExDay, 5, 2)
    sDay = Left(Right(fromExDay, 4),2)
    'fromExDay = sYr + sMonth + sDay    
    fromExDay = sYr + sMonth + sDay
    sYr = Right(Left(toExDay, 4),2)
    if sYr <> "99" then
        sYr = LEFT(CStr(CDbl(sYr) + 12),2)
    end if
    sMonth = Mid(toExDay, 5, 2)
    sDay = Left(Right(toExDay, 4),2)
    toExDay = sYr + sMonth + sDay    
    'toExDay = Right(fromExDay, 2)
    Formula = fromExDay + " ~ " + toExDay    
Else
    Formula = ""
End If

Value of ExchangeFrom and ExchangeTO is coming from Database . ExchangeFrom value = 20031031 ExchangeTo value = 200 Is There in Database

return 值应该是

151010 ~ 1220

将其转换为 SSRS VB 函数实际上不需要太多更改。在 SSRS 中,该函数不直接与字段一起使用,因此您需要将它们作为参数传递给函数。旧函数中的其余大部分 VB 应该在 SSRS 中工作相同 - 我只是删除了 SSRS 中没有的 ToText 函数。

当您从文本框中调用该函数时,您将传递字段。

=code.Formula1(Fields!HktrExchngDayFrom.Value, Fields!HktrExchngDayTo.Value)

函数如下:

Public Function Formula1(ByVal fromExDay as String, ByVal toExDay as String) as String

Dim sYr as String
Dim sMonth as String
Dim sDay as String

fromExDay = Replace (fromExDay, ",", "" )
fromExDay = Replace (fromExDay, ".", "" )

toExDay = Replace (toExDay, ",", "" )
toExDay = Replace (toExDay, ".", "" )

if Len (Trim(fromExDay)) > 0 and Len (Trim(toExDay)) > 0 then
    sYr = Right(Left(fromExDay, 4),2)
    if sYr <> "99" then
        sYr = LEFT(CStr(CDbl(sYr) + 12), 2)
    end if
    sMonth = Mid(fromExDay, 5, 2)
    sDay = Left(Right(fromExDay, 4), 2) 
    fromExDay = sYr + sMonth + sDay
    sYr = Right(Left(toExDay, 4), 2)
    if sYr <> "99" then
        sYr = LEFT(CStr(CDbl(sYr) + 12), 2)
    end if
    sMonth = Mid(toExDay, 5, 2)
    sDay = Left(Right(toExDay, 4), 2)
    toExDay = sYr + sMonth + sDay 
    Formula1 = fromExDay + " ~ " + toExDay    
Else
    Formula1 = ""
End If

End Function 

我认为 sDay 计算不正确。

sDay = Left(Right(fromExDay, 4),2)      

好像又要过月了。应该是

sDay = Right(fromExDay, 2)

或者,如果它可以是更长的字符串,请使用 MID:

sDay = Mid(fromExDay, 7, 2)

将结果更改为:

151031 ~ 12

为了制作这个公式,我在 Active Report 页面中使用了两个文本框,并将这个公式分成了两个部分。

文本框 1:

=iif(Right(Left( Fields!ExchngDayFrom.Value , 4),2)  <> 99 ,LEFT(CStr(CDbl((Right(Left( Fields!ExchngDayFrom.Value , 4),2) ) + 12),2) + Mid( Fields!ExchngDayFrom.Value , 5, 2) + Left(Right( Fields!ExchngDayFrom.Value , 2),2 ) ," ")

假设 ExchangeDayfrom 的值为:20031031 输出为 151031

文本框 2:

="~ " & iif(Right(Left( Fields!ExchngDayTo.Value , 4),2) <> 99 ,LEFT(CStr(CDbl((Right(Left( Fields!ExchngDayTo.Value , 4),2)) + 12),2)  + Mid( Fields!ExchngDayTo.Value , 5, 2) +  Left(Right( Fields!ExchngDayTo.Value , 2),2 ) , Right(Left( Fields!ExchngDayTo.Value , 4),2) + Mid( Fields!ExchngDayTo.Value , 5, 2) +  Left(Right( Fields!ExchngDayTo.Value , 2),2 )

假设 ExchangeDayTo 的值为:99999999 输出为~999999

This is How I Solve my Problem.Big thanks to @Hannover Fist sir thanks Your valuable Solution and Yes Your Solution is Right it's also worked Perfectly