cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Crystal Report Database Query

Former Member
0 Likes
247

Hi I would like to ask regarding queries from the database. I have 2 main tables that gets their images from 1 master table.

First is TASK table and Second is ASSET table. Both tables are relational.

Each Task has Asset connected by Task_Asset_ID.

But both tasks and each assets may have also images from the Image table thru Assignment table. But I am wondering how could I query the data to show tasks with images and assets with images in one row.

For example

Task 1 may have Green.jpg

Asset 222 may have Red.jpg

Knowing that Task and Asset are relational, is it possible to show them in one row in crystal report?

.

Task

TaskIDTaskNameTask_Asset_ID

1

Task1111
2Task2222
3Task3

111

Asset

AssetIDAssetName
111Asset1
222Asset2

Images

imgIDImgName
1Red.jpg
2Yellow.jpg
3Blue.jpg
4Green.jpg

Assignment

AssIDTaskOrAssetIDImgIDType
114X
22221Z
333Z
41112X

Accepted Solutions (1)

Accepted Solutions (1)

DellSC
Active Contributor
0 Likes

Ok, this is going to get a bit complicated, but this is possible.  The problem is that the Assignment table records can have either TaskID or AssetID, so you're going to have to use some tables twice with aliases.

Here's what I'd do...

In the Database Expert:

1.  Add all of the tables to your report.

2.  Add a second copy of Assignment and Images - when you do this, Crystal will warn you that the table is already in the report and ask if you want to "alias" it.  At that point it will add the table with "_1" at the end of the table name.  So, you'll have Assignment_1 and Images_1.

3.  On the linking tab, create the following links:

     Task.Task_Asset_ID to Asset.AssetID

     Task.TaskID to Assignment.TaskOrAssetID - make this a left outer join (see below)

     Assignment.ImgID to Images.ImgID - make this a left outer join

     Asset.AssetID to Assignment_1.TaskOrAssetID - make this a left outer join

     Assignment-1.ImgID to Images_1.ImgID - make this a left outer join.

To make a left outer join, right-click on the join and select "Join Options".  Select "Left Outer" and save the join.  Left outer joins will provide data even when there is no matching value in the table that you're linking to - the values from that table will be null.

In your report:

1.  Put the following column headers on the report:

     Task Name

     Task Image

     Asset Name

     Asset Image

2. Put the following fields in the details of the report:

    {Task.TaskName}

    {Images.ImgName}

    {Asset.AssetName}

    {Images_1.ImgName}

3. Sort the data by Task Name and Asset Name.

-Dell

Former Member
0 Likes

Thank You!

Answers (0)