解析Crystal Reports中的奇怪字段

时间:2009-08-12 14:33:31

标签: crystal-reports

我正在使用Crystal Reports Basic for Visual Studio 2008从数据库生成报告。在数据库中有一个称为数据的“结构化数据”字段。 这是一种表示Hashtable的方式,格式为:

XLLLKeyYMMMValue
where:
X is the length of the length of the Key
L is the length of the Key
Y is the length of the length of the Value
M is the length of the Value

所以,如果我要编码

Name = John Robert Oxley
Age Of Poor Little Developer = 27

我会的。

Name (L = 4 therefore X = 1)
John Robert Oxley (M = 17 therefore Y = 2)
Age Of Poor Little Developer (L = 28 therefore X = 2)
27 (M = 2 therefore Y = 1)

所以此记录的字段将包含

14Name223John Robert Oxley228Age Of Poor Little Developer1227

报告中有许多我想知道的字段。但是,它们可能不在表中的数据字段中。现在我的问题

  • 我猜我必须创建一个自定义函数parseStructuredData(data,field),它返回我想要的字段,如果不存在则返回null。
  • 网上是否有自定义功能的资源或我应该为Crystal Reports购买的书籍(最好是电子书),因为我的经验很少?
  • 然后我使用“公式字段”将其放在报告上吗?

更新这是在MS SQL服务器上运行但我不想使用存储过程来解析数据,因为我不想修改数据库。

2 个答案:

答案 0 :(得分:2)

我在你的编辑中看到你不想修改数据库,但是如果没有一个存储过程将它转换成更多的表格视图,那么获取你正在寻找的输出将是非常困难的。即使你能够在Crystal中做到这一点,我想你必须使用循环和字符串操作,在每一行上执行这些计算会非常慢并且处理器密集。

我建议您在存储过程中使用T-SQL或临时表格式化数据,而不是尝试在Crystal中执行此操作。在SQL Server中使用游标可能会更慢,我相信它会比在Crystal中快得多。

编辑:我错过了你说使用VS2008这样做的部分。如果您不想在SP中执行此操作,因为您不想更改数据库,则可以创建一个函数来执行此操作,该函数将ArrayList或DataTable作为报告数据源传递。

我会尝试重新研究一下并编辑我的答案,以提供我如何在存储过程或函数中执行此操作。

答案 1 :(得分:1)

这是我的功能。它比罪恶更丑陋,我觉得羞于在互联网上发布这个。但它的确有效。之前没有使用过VB,所以请点击这里:

Function ParseStructData (struct As String, key As String) As String
    Dim leng As Number
    Dim ll As Number
    Dim data As String
    Dim rest As String
    Dim kk As String

    rest = struct

    Do
        ll = Val(Left(rest, 1))
        If ll < 1 Then
            Exit Function
        End If
        rest = Right(rest, Len(rest) - 1)
        leng = Val(Left(rest, ll))
        rest = Right(rest, Len(rest)-ll)
        kk = Left(rest, leng)
        rest = Right(rest, Len(rest)-leng)
        ll = Val(Left(rest, 1))
        rest = Right(rest, Len(rest)-1)
        leng = Val(Left(rest, ll))
        rest = Right(rest, Len(rest)-ll)

        data = Left(rest, leng)
        If kk = key Then
            ParseStructData = data
            Exit Function
        End If
        rest = Right(rest, Len(rest)-leng)
    Loop Until Len(rest) <= 0

End Function

如果有人能提出更好的功能,请回答。

相关问题