Command in Crystal

 3 Replies
 0 Subscribed to this topic
 22 Subscribed to this forum
Sort:
Author
Messages
mil0n023
Veteran Member
Posts: 63
Veteran Member
    I am currently developing an Employee Review report - linking 3 tables (EMPLOYEE, PAEMPLOYEE, & REVIEW) now I want to add a command to just provide an Employees most recent Last Review - does this look correct? Also, will adding a command along with tables that are linked - jeopardize the report at all?

    Here is the command:
    SELECT REVIEW.EMPLOYEE, REVIEW.ACTUAL_DATE,
    FROM LAWSON.REVIEW REVIEW,
    WHERE REVIEW.ACTUAL_DATE = (SELECT MAX(REVIEW.ACTUAL_DATE)
    FROM LAWSON.REVIEW REVIEW
    WHERE REVIEW.EMPLOYEE = REVIEW.EMPLOYEE)
    Thanks!
    M. C. Miller
    Analyst
    Salem, Oregon
    John Henley
    Posts: 3353
      That's close, but not quite, since your "REVIEW" aliases are named the same in the outer and inner queries. In addition, you have a few too many commas. Regardless, what you're asking for doesn't even require a nested query; you can do it with a single query:

      SELECT REVIEW.EMPLOYEE, MAX(REVIEW.ACTUAL_DATE)
      FROM LAWSON.REVIEW REVIEW
      GROUP BY REVIEW.EMPLOYEE

      This will generate a list of employees WHO HAVE HAD REVIEWS and their latest review date.

      You then should LEFT JOIN to this resultset so that your report will include employees who don't have reviews; if you just did a JOIN (or INNER JOIN), it would drop employees without reviews from your report.

      A final note on nested queries: ALWAYS ALWAYS ALWAYS (and yes ALWAYS) make sure you include the full PRIMARY KEY in the WHERE clause. In your example, you only had EMPLOYEE. You should include COMPANY as well, otherwise you will be doing a table-scan (read: bad performance!) when the join is performed.
      Thanks for using the LawsonGuru.com forums!
      John
      mil0n023
      Veteran Member
      Posts: 63
      Veteran Member
        John - thanks!

        I decided to go the traditional Database Expert and use the Crystal Functionality. But, NOW, the way I have this report built, with various dates, and an Nth Largest =1 on a particular date field, I am placing my results in the Group Header. I have 2 Groups - 1)Employee Home Dept # 2) Employee #

        How can I get this report to sort by one of the date fields? (Next Review - managers want too see the oldest date first) It does not sort at all...
        M. C. Miller
        Analyst
        Salem, Oregon
        John Henley
        Posts: 3353
          Insert a group on next review and suppress the group header/footer.
          Thanks for using the LawsonGuru.com forums!
          John