Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: SQL command issue Post Reply Post New Topic
Author Message
johnwsun
Senior Member
Senior Member


Joined: 28 May 2008
Location: Australia
Online Status: Offline
Posts: 179
Quote johnwsun Replybullet Topic: SQL command issue
     Posted: 04 Nov 2009 at 8:30pm
Hi All,
 
I have a report that consists of two parts: one part is focused on students who have overdued item loans from the library; the other part is the staff who runs the report with some staff related information.
 
The first part is a normal record selection, with the second part I use first SQL command to retrieve staff who runs the report; I created another SQL command to retrieve staff who has the authority. Both commands are actually same (they know who is a general staff, who is the authoriser).
 
I also created a view on the SQL DB server which populated all library staff (not linked to any table, nor do the commands), and passing the selected staff as parameter to the command
 
Both commands are inner joined with tables. The problem is when one of the table (stores staff emails) has NULL value, (no link to other table), the report is crashed. On the SQL server I use the same SQL and found that if one of staff has no email, the SQL still runs, but this staff is not retrieved.
 
OK, if I changed to left outer join, all staff with or without email will be retrieved from SQL server.  So I changed the left outer join in SQL command in Crystal Reports XI, and when running, I found the report is in loop, never ends!
 
With the previous command (inner join one), if I selected a staff who happens to have email, the report runs OK  with students with overdue loans in the report as well as staff details.
 
My command looks liek below:
SELECT TEXT as EMAIL, NUMBER, HEAD, DEPT, POSN,ALL_INSTITUTIONS.TXT AS CAMPUS FROM BDE
INNER JOIN UDT ON BDE.IRN = UDT.IRN
INNER JOIN HEADING ON UDT.IRN = HEADING.IRN
INNER JOIN BDT ON UDT.IRN = BDT.IRN
INNER JOIN  INS ON INS.IRN = UDT.BRANCH
INNER JOIN ALL_INSTITUTIONS ON ALL_INSTITUTIONS.CODE = INS.CODE
BDE is the table which stores email,
TEXT is email address,
NUMBER is telephone number, HEAD is the staff name, DEPT is department,
POSN is staff position, Campus of course.
These tables should not be linked to the student tables in this design, as  a staff may run this report against several campuses.
 
The report has group on student names with their overdue loans in the detail secion. The staff details are in the group footer. My customer insists they (student and staff )both have to appear on the same page.
the report looks like a form which things like explanation, signature, etc.
It's not necessary that a staff has to have email address in a sense.
 
could anyone please advise on the above problem? Thanks in advance.
 
John


Edited by johnwsun - 04 Nov 2009 at 8:34pm
IP IP Logged
kevlray
Admin Group
Admin Group
Avatar

Joined: 29 Oct 2009
Online Status: Offline
Posts: 1587
Quote kevlray Replybullet Posted: 06 Nov 2009 at 10:08am
I am not sure why the report is looping.  Do you have access to run the query from the database directly, just to see how many rows are returned?
 
 
IP IP Logged
johnwsun
Senior Member
Senior Member


Joined: 28 May 2008
Location: Australia
Online Status: Offline
Posts: 179
Quote johnwsun Replybullet Posted: 08 Nov 2009 at 2:33pm
Hi Kevlray,
 
Yes, if I directly query the database, I can get row to return expectedly.
with inner join:
On the SQL server I use the same SQL and found that if one of staff has no email, the SQL still runs, but this staff is not retrieved.
with left outer join:
all the staff returned with or without email address
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 09 Nov 2009 at 6:25am
Using a command object to retrieve data as the main data retrieval is problematic, as you have seen.  Since there are 2 commands, that is my guess as to why it is looping.  My theory has always been that the command object was 'created' to supply the parameter screen with 'dynamic' data from the database so that the 'old' style of static lists could be made 'live' on the parameter selection.  Using the command object for anything else...well the results can be unpredictable.  Yes, many people use them as the main datasource, and then have problems. 
 
I'm saying how to write a report, but I believe that the preferred method is a)via stored proc/view b)joining to the tables directly c)pushing the data to the report.  If possible I would try changing the report to one of these methods and see if that solves the issue.
 
What CR is probably 'seeing', is one command gets info, it then trys to fill the second command, thinks it needs something, calls the first command, and the loop is complete.
 
HTH
IP IP Logged
johnwsun
Senior Member
Senior Member


Joined: 28 May 2008
Location: Australia
Online Status: Offline
Posts: 179
Quote johnwsun Replybullet Posted: 09 Nov 2009 at 2:47pm
Hi Lockwelle,
 
I was thinking of using a View, but does the view have to have links to other tables(in my circumstances, the staff related 'View' should not link to student tables).
With the current approach, command object,if it's inner join, it works OK when email address is not NULL. if it's NULL, it's crashed on running. Using left outer join in command object, it looks like looping.
John
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 10 Nov 2009 at 6:04am
I don't use views much, but views are basically precoded select statements, so they can join to other tables, but they don't have to.
IP IP Logged
johnwsun
Senior Member
Senior Member


Joined: 28 May 2008
Location: Australia
Online Status: Offline
Posts: 179
Quote johnwsun Replybullet Posted: 20 Nov 2009 at 3:58pm
Hi Lockwell,
 
I am trying to use stored procedure and found a problem:
When I put sp_xxx from availabel data sources to the selected tables, it prompts to enter value, I just select the checkbox to 'set null value'- which to me this is OK.
Then I drag the fields from sp_xxx to the reports. Obviously, the parameter appears in the Field Explorer -> Parameter fields. I click the sp parameter name and choose Edit -> select dynamic -> choose one  field as the Value from a view.
then I drag the sp parameter to the report and suppress it.
When the report is being run, this parameter has prompted two times: once by itself with 'Set null ' not checked. If I ticked 'Set Null' check box, it will prompt a second time with other parameters such as date range, etc.
I wonder if there is any way to prevent it from prompting two times of the sp parameter? Or the sp parameter can be edited in parameter fields as Dynamic, if it is not, it's not useful?
Could you please advise?
Thanks in advance.
 
John
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 23 Nov 2009 at 6:15am
It's been a few years since I needed/had to interact with the CR parameter screen.  Yes, they can be dynamic, I remember that I have done that. I don't know about displaying twice as I never had that problem, but to suppressing it, I doubt it...you would need to determine why CR is prompting.  Something like: there is a subreport that is not linked correctly that uses the same parameter/sp would trigger CR to prompt. 
 
Not that this would cause it, but why are dragging the parameter to the report and then suppressing it? A parameter is like a global variable, it is always available in the report.
 
 
IP IP Logged
johnwsun
Senior Member
Senior Member


Joined: 28 May 2008
Location: Australia
Online Status: Offline
Posts: 179
Quote johnwsun Replybullet Posted: 25 Nov 2009 at 4:12pm
Hi Lockwelle,
 
There is no such problem in Crystal Report 2008 where the sp parameters won't prmmpt two times; I have run and test the report created in XI, no problems!
Cheers,
John
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