WalterHeisenberg
Technical User
- Mar 28, 2008
- 159
Hello,
I am trying to write a crystal report and working in a very goofy database. The issue I've run into is that I need to pivot out the results of rows into distinct columns.
So the field I'm working with, WDLINESEQ has values of 1,2,3,4 etc. If it is a 1 it needs to be in column web, if it is 2 it needs to be in column tv etc.
The problem is table A has 1 row and has a FK that exists in every row of table 2. I don't see any other way to join these tables so I'm stuck with if table B has 6 results it shows up 6 times in the detail section with 1 column having a value and the rest being null.
In SQL I would solve this by pivoting out the data in a subquery and using that as my from in new query that selected the standard rows and max() of the pivoted fields grouping on the standard rows. Not sure how to do this in Crystal.
I've attached a sample of a SQL query that achieves the desired result.
The result returned by this query is:
I can't use something like SUM(CASE because these conversions will only have 1 field that is populated with an actual text value I will be returning. All 6 fields will be populated. I hope I explained this well. Thanks in advance.
I am trying to write a crystal report and working in a very goofy database. The issue I've run into is that I need to pivot out the results of rows into distinct columns.
So the field I'm working with, WDLINESEQ has values of 1,2,3,4 etc. If it is a 1 it needs to be in column web, if it is 2 it needs to be in column tv etc.
The problem is table A has 1 row and has a FK that exists in every row of table 2. I don't see any other way to join these tables so I'm stuck with if table B has 6 results it shows up 6 times in the detail section with 1 column having a value and the rest being null.
In SQL I would solve this by pivoting out the data in a subquery and using that as my from in new query that selected the standard rows and max() of the pivoted fields grouping on the standard rows. Not sure how to do this in Crystal.
I've attached a sample of a SQL query that achieves the desired result.
Code:
SELECT TXSITE, TXCFOV, NMCFOC, MAX(sev) as Web, MAX(twlv) as TV
FROM
(
select s.TXSITE, s.TXCFOV, s.NMCFOC
,case when WDLINESEQ = 7 then '1' end as sev
,case when WDLINESEQ = 12 then '1' end as twlv
from VMSITE s
join VMCFOC c on c.TXCFOV = s.TXCFOV and s.NMCFOC = c.NMCFOC
where s.TXSITE = '1100') X
Group by TXSITE, TXCFOV, NMCFOC
The result returned by this query is:
Code:
TXSITE,TXCFOV,NMCFOC,Web,TV
1100 ,CF1 ,1059,1,1
I can't use something like SUM(CASE because these conversions will only have 1 field that is populated with an actual text value I will be returning. All 6 fields will be populated. I hope I explained this well. Thanks in advance.