Print Page | Close Window

SQL expression fields - link back to report table

Printed From: Crystal Reports Book
Category: Crystal Reports 9 through 2020
Forum Name: Report Design
Forum Discription: The best way to design a report and problems you have encountered
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=15426
Printed Date: 30 Apr 2024 at 2:16pm


Topic: SQL expression fields - link back to report table
Posted By: JVDB
Subject: SQL expression fields - link back to report table
Date Posted: 23 Jan 2012 at 5:06am

I started to explore sql expression fields some weeks ago but I have the following problem :

Our database has 3 main tables : workorder, operations and materials
 
This workorder table contains the header information but also the more detailed level information.
 
This header information can be filtered out by a specific column.
 
WORKORDER
 
ID DETAIL   PART
A     0          PARTNUMBER
A     1          EMPTY
A     2          EMPTY
 
In the crystal report I put all records from this workorder table but now I want to add this PART information only from ID = 'A' and DETAIL = '0' by using a sql expression fields.
 
I tried it like this
(
SELECT WORKORDER.PART
FROM WORKORDER
WHERE WORKORDER.ID = WORKORDER.ID AND WORKORDER.DETAIL = 0
)
 
If I change WORKORDER.ID into 'A' I have off course the correct answer.
 
If something like this is impossible I have also a view that I can use
 
(SELECT WORKORDERVIEW.PART
FROM WORKORDERVIEW
WHERE WORKORDERVIEW.ID = WORKORDER.ID
)
=> in this view I filtered out all the records with DETAIL = '0'
But this is also not working.
 
I keep on getting errors about WORKORDER.ID can't be bound or that this is



Replies:
Posted By: hilfy
Date Posted: 23 Jan 2012 at 5:54am

Your problem is in your where clause - "Where WORKORDER.ID = WORKORDER.ID will get you all of the data in the table.  Instead you need to alias the Workorder table your SQL expression.

This is probably going to slow down your report though.  A better way to do this would be to go to the Database Expert and add the Workorder table to your report a second time.  Crystal will alert you that the table is already in the report and ask you if you want to alias it - click on Yes (or maybe it's OK....)  The table will then appear in the list of selected tables as "WORKORDER_1".  Link from WORKORDER.ID to WORKORDER_1.ID.  Then, in the Select Expert set a filter on WORKORDER_1.DETAIL = 0.
 
-Dell


-------------
Proviti, Data & Analytics Practice
http://www.protiviti.com/US-en/data-management-advanced-analytics - www.protiviti.com/US-en/data-management-advanced-analytics


Posted By: JVDB
Date Posted: 01 Feb 2012 at 11:38pm
I tried to put the alias in the sql but also this is not working
(
SELECT WORKORDER_1.PART
FROM WORKORDER WORKORDER_1
WHERE WORKORDER_1.ID = WORKORDER.ID AND WORKORDER_1.DETAIL = 0
)



Print Page | Close Window