开发者

Crystal Reports: data in records is stored in columns in a row, how can I transpose those columns or choose maximum from them?

开发者 https://www.devze.com 2023-03-17 02:58 出处:网络
I have a legacy database in which data is stored in a way similar to: id,a1,a2,a3,a4,a5...,a20,b1,b2,b3,b4,...,b20,c1,c2,c3,c4,...,c20

I have a legacy database in which data is stored in a way similar to:

id,a1,a2,a3,a4,a5...,a20,b1,b2,b3,b4,...,b20,c1,c2,c3,c4,...,c20

My task is to select top 3 values from the b columns and print corresponding a and c values. So, if the max values are in b5,b1,b17 then I need to print on the report something like this:

a5, b5, c5
a1, b1, c1
a17, b17, c17

I tried using pivot ta开发者_Python百科bles and cross tabs, yet with no luck (well, this may be the result of the fact, that I have only basic understanding of Crystal Reports).

May I ask for some tips or guidelines to how can I achieve this?

Thank you.


Unfortunately, Crystal Reports doesn't have an Eval() function, which would certainly help.

Here's a hack-ish approach:

  1. create a Detail section for each field set: aX, bX, cX--there will be 20 such sections. So, Details a would contain a1, b1, c1; Details b would contain a2, b2, c2. You get the idea.
  2. determine which b columns contain the maximum values; store these column # in an array, perhaps
  3. hide/show each detail section by comparing its index (letter of the alphabet) to the array of column indicies.

Another approach is to create a UNION query in the report's Command:

SELECT ID, 1 as idx, a1 as A, b1 as B, c1 as C

UNION 

SELECT ID, 2 as idx, a2 as A, b2 as B, c2 as C

...

UNION

SELECT ID, 20 as idx, a20 as A, b20 as B, c20 as C

Reporting on this approach is trivial.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号