Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2020 : Technical Questions
Message Icon Topic: Joining tables from one column to discrete columns Post Reply Post New Topic
Author Message
crystalsonic
Groupie
Groupie


Joined: 26 Jan 2012
Online Status: Offline
Posts: 46
Quote crystalsonic Replybullet Topic: Joining tables from one column to discrete columns
    Posted: 29 Jan 2015 at 10:19am

I have a report with a Main report and a Subreport. I am able to join those two without any issues.

The subreport contains two tables: A and B. 
     Table A has Column A1 and A2.
         Column A2 is what I am using to join to the Main Report.
         Column A1 is a string separated by ~
               A~B~C~D~E
 
     Table B has Columns W,X,Y and Z
               Column W (String)
               Column X (String)
               Column Y (Number)
               Column Z (Number)
 
I was able to split Column A into separate fields.
       B (output is string) is equivalent to Column W in Table B
       D (output is string) is equivalent to Column Y in Table B
       E (output is string) is quivalent to Column Z in Table B
 
I am interested in Column X from table B.
 
Aside from trying to link two tables together based on a string in a column to discrete columns on a another table, I am also having problems using variables that come out as a string from the split column and trying to join them to table B where the column is stored as a number.
 
Any help is greatly appreciated.
 
I tried using shared variables and taking them from the subreport to the main report. Then adding a second subreport to get the data from Table B. I did not have any luck because of the different data types.
 
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3701
Quote hilfy Replybullet Posted: 30 Jan 2015 at 4:26am
Your best bet for this is probably going to be to use a Command in the subreport instead of tables.

A command is just a SQL Select statement. If you'll let me know what type of database you're connecting to, I should be able to come up with some sample SQL that will show you how to do this.

-Dell
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3701
Quote hilfy Replybullet Posted: 30 Jan 2015 at 5:41am
For example, in SQL Server you could use this:

With AData as
    Select
      SUBSTRING(A.A1, t1+1, t2-t1-1) as b,
      REVERSE(SUBSTRING(revStr, trev1+1, trev2-trev1-1)) as d,
      REVERSE(LEFT(revStr, trev1-1)) as e

    from
      (select
          REVERSE(A.A1) as revstr,
          CHARINDEX('~', A.A1) as t1,
          CHARINDEX('~', A.A1, CHARINDEX('~', A.A1) + 1) as t2,
          CHARINDEX('~', REVERSE(A.A1)) as trev1,
          CHARINDEX('~', REVERSE(A.A1), CHARINDEX('~', REVERSE(A.A1)) + 1) as trev2
        from A
        where A.A2 = {?Link From Main Rpt}
      ) as positions
      
Select b.X
from AData
inner join B
    on AData.b = B.W
      and AData.d = B.Y
      and AData.e = B.Z

You'll need to create the parameter in the Command Editor - Commands can't see parameters that are created in the report. Then, in your Subreport Links, you'll link from the field in your main report, UNCHECK "Select data on subreport based on field" and then select the parameter from the command in the drop-down list on the bottom left. This will link the data from the main report directly to the parameter in the command.

-Dell
IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.031 seconds.