[英]How to Write this Crystal Report formula in SSRS Expression?
我在转换SSRS表达式中的此Crystal Report公式时遇到问题,有人可以帮助我吗?
公式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
ExchangeFrom和ExchangeTO的价值来自数据库。 ExchangeFrom值= 20031031 ExchangeTo值= 200数据库中是否存在
返回值应该是
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
为了制作此公式,我在“活动报表”页面中使用了两个文本框,并将该公式分为两个部分。
文字框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
TextBox2:
="~ " & 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
这就是我解决问题的方法。非常感谢@Hannover Fist先生,谢谢您的宝贵解决方案,是的,您的解决方案是正确的,它也可以完美地工作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.