Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: Join tables - Use table as reference. Post Reply Post New Topic
Author Message
Edgardini
Newbie
Newbie


Joined: 02 Aug 2010
Location: United States
Online Status: Offline
Posts: 2
Quote Edgardini Replybullet Topic: Join tables - Use table as reference.
     Posted: 02 Aug 2010 at 3:23pm
Hello,
 
I am fairly new to Crystal Reports and to SQL, sorry about the simple question.
 
It is about joining data from two databases.
 
Example:
Table Auto.Makers
Make       Doors    Cylinders AvgCost
Mazda     4             6            17000
Ford        2             6            16000
Toyota     4            6             19000
 
Table Multiple.Cost
Make   Year    Cost 
Mazda 2008   0
Mazda 2009   0
Mazda 2010   0
Ford    2008   0
Ford    2009   0
Ford    2010   17000
Toyota 2008  0
Toyota 2009  0
Toyota 2009  0
 
The tables are just examples for another type of data.
 
I want a report of the cost of a car on 2010, if it did not have a cost I would like a line per auto on the automaker table and an empty field for cost. I will use the cost field for further calculations.
 
What I would like to get is something like this:
Make       Doors    Cylinders Year  Cost       Avg       Diff
Mazda     4             6
Ford        2             6            2010 17000    16000   1000
Toyota    4             6
 
If I join the databases I get multiple lines that I dont' want.
Make       Doors    Cylinders Year Cost       Avg       Diff
Mazda     4             6            2008 0
Mazda     4             6            2009 0
Mazda     4             6            2010 0
Ford        2             6            2008 0
Ford        2             6            2009 0
Ford        2             6            2010 17000    16000   1000
Toyota    4             6             2008 0
Toyota    4             6             2009 0
Toyota    4             6             2010 0
 
If I do a SELECT using costs on 2010 greater than 0, I don't get a line for the records that did not have a cost on 2010.
 
What is the best option to follow? I will try and read more on anything suggested.
 
Thanks
IP IP Logged
Emir_W
Senior Member
Senior Member
Avatar

Joined: 25 Apr 2010
Online Status: Offline
Posts: 228
Quote Emir_W Replybullet Posted: 02 Aug 2010 at 7:24pm
try from sql:
select a.*, b.*
from auto.makers a
join multiple.cost b on a.make=b.make
where b.cost>0
 
 
hope it help.
 
Emir W
IP IP Logged
Edgardini
Newbie
Newbie


Joined: 02 Aug 2010
Location: United States
Online Status: Offline
Posts: 2
Quote Edgardini Replybullet Posted: 03 Aug 2010 at 1:15pm
Thanks for the reply.
 
The suggested SQL instruction would only show one record, correct? The auto.makers record that has a multiple.cost in 2010.
 
I want to show records from auto.makers even if they don't have a cost or record in 2010.
 
I tried using a SQL command object and that worked almost perfectly. I was able to filter the Multiple.Cost table on year 2010 records and then left joining the tables. The problem is that the report that I am trying to make is used on several databases and it seems the command object does not change as need.
 
Using a subreport works also, it seems I would need to get the variable needed from the subreport.
 
Using a SQL Expression picked the correct cost up but somehow repeated records depending on how many records the multiple.cost has.
 
What I am trying to figure out using Crystal Reports XI, what is the common way to pick and choose information from a secondary table.
 
Thanks
IP IP Logged
Emir_W
Senior Member
Senior Member
Avatar

Joined: 25 Apr 2010
Online Status: Offline
Posts: 228
Quote Emir_W Replybullet Posted: 04 Aug 2010 at 3:40pm
have you try to group it?
 
you can group it based on 'Make' and make some summary for other fields.
 
 
hope it help.
Emir W
IP IP Logged
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