Query syntax error

 4 Replies
 0 Subscribed to this topic
 22 Subscribed to this forum
Sort:
Author
Messages
DavidBrianCampbell
Basic Member
Posts: 13
Basic Member
    Thanks in advance... I have a manually written query I'm testing to join 3 name fields into one field. Here's what I have which needs to output in a format like "Doe, John M.":

    SELECT EMPLOYEE.EMPLOYEE, ([EMPLOYEE.LAST_NAME] & ", " & [EMPLOYEE.FIRST_NAME] & [EMPLOYEE.MIDDLE_INIT] &".") AS FULLNAME,
    FROM EMPLOYEE

    I get an Oracle 936 "missing operation" message. Any clues?
    Chris Martin
    Veteran Member
    Posts: 277
    Veteran Member
      Sounds like you are looking for sql query against an Oracle database. If so, try this:

      select employee,
      trim(last_name) || ', ' || trim(first_name) || ' ' ||
      case when trim(middle_init) is null then trim(middle_init) else trim(middle_init) || '.' end
      from employee
      John Henley
      Posts: 3353
        Remove the comma from the end of FULLNAME.
        Thanks for using the LawsonGuru.com forums!
        John
        John Henley
        Posts: 3353
          If you are entering the SQL directly into Crystal via a command, it has to be in the syntax of the database you're querying...
          The syntax you're using will work against SQL server, but not sure about Oracle (I think Chris is correct in that you need the || characters....)
          In fact, since Chris has written the code for you, you owe him lunch!
          Thanks for using the LawsonGuru.com forums!
          John
          Chris Martin
          Veteran Member
          Posts: 277
          Veteran Member
            The query I indicated should work, but I did leave off the renaming of the "full name" field. This one should be cleaner:

            select employee,
            trim(last_name) || ', ' || trim(first_name) || ' ' ||
            case when trim(middle_init) is null then trim(middle_init) else trim(middle_init) || '.' end as full_name
            from employee