I’m trying to create (what I thought was) a simple Crystal Report. Essentially, I want to produce a report that lists, for instance, each time a student has received some kind of disciplinary action:
╔═══════════╦═════════════╦════════════╦══════════╗
║ StudentID ║ StudentName ║ Action ║ Date ║
╠═══════════╬═════════════╬════════════╬══════════╣
║ 1 ║ Smith, John ║ Suspension ║ 1/1/2012 ║
║ 2 ║ Q, Susie ║ Detention ║ 1/5/2012 ║
║ ... ║ ... ║ ... ║ ║
╚═══════════╩═════════════╩════════════╩══════════╝
However, this information is stored in the database as three separate tables:
- Student information, such as their ID and name.
- Disciplinary actions, including the student’s ID, date, and a code indicating what kind of action was taken.
- A table that pairs each code with a description of the action, so 1 maps to “Detention”, 2 maps to “Suspension”, etc.
I am not sure how to link these columns in Crystal Reports, specifically so that I can display a column describing the action taken rather than just the code. I thought that a SQL Expression field could accomplish this, like so:
(
SELECT "ActionCodes"."ActionDesc"
WHERE "DisciplinaryActions"."ActionCode" = "ActionCodes"."ActionCode"
)
Adding this field to my report only produces blank rows, unfortunately. Am I on the right track and am just fumbling with my query, or is there a better route?
In Crystal Reports, you would need to go to Database Expert, navigate to the database you are retrieving the table from. Then using the > button in the middle of the screen, move all the tables over to the right: Student, Disciplinary, Description.
You would then have to create left outer joins.
From the Student table, select StudentID and drag it over to the Disciplinary’s StudentID.
You should see a join that shows an arrow from Student to Disciplinary —>
After that, left outer join Disciplinary Code with Description Code.
Once you have the joins correct, you should be able drag and drop the different fields you need in to the report.
You could use the SQL Expression option, but doing the joins will be easier and you also have the flexibility of being able to use Disciplinary Code or the Description in the future.
If you need step-by-step instructions with screenshots, let me know.