Solved

How Do I write a query for three Database Field SQL queries as the Datasource

Posted on 2011-03-15
4
517 Views
Last Modified: 2012-05-11
Good day!
I am having trouble trying to write the SQL statement to join the SQL Tables in my Database Expert. I have 3 tables. (1)Base, (2)OOHEADNotes, and (3) OOLINENotes.  The 3 tables are SQL statements off one database, which  is a DB2.
My goal is to have a text label field in the report with the SQLformula 'OrderHeadNotes' which would be like:
SELECT OOHEADNOTES.OATX60 FROM OOHEADNOTES as OO
INNER JOIN BASE as B ON (OO.OATXID=B.OATXID or OO.OAPOTX=B.OAPOTX or OO.OAPRTX=B.OAPRTX)

I need the actual Notes field (OATX60) based on the PK's of BASE (OATXID,OAPOTX,OAPRTX) joined to the FK's of OOHEADNotes(OATXID, OAPRTX, OAPOTX).

I have included the report.
OpenOrders-AddOrderHeadNotes-Ph3.sql
0
Comment
Question by:leason2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 37

Expert Comment

by:momi_sabag
ID: 35141820
could you provide the tables definition with sample data and the desired output?
your description is hard to follow
0
 

Author Comment

by:leason2
ID: 35142476
Here go. I included 2 screenshots.  (1) is the TableDefinitions. (2) is ReportExample. In TableDefinitions, the upper list of fields missing the header belong to table "Base".
In ReportExample, the TextLabel listing "OOHeadNotes Here" is where I need to list the resultset  of the OrderHead Notes.

I will then do the same for OOLineNotes, but with the explanation of how to format the SQL correctly I can add the LineNotes myself.

I need to return all occurrences of field (OOHEADNOTES.OHEADNOTES) for every Order Number( Base.OBORNO) and list them into the TextLabel in the report.
Here is how I would write it in plain SQL. But Crystal doesn't like it.
The join is interesting, because an OrderNo (OBORNO) has three different versions of notes. Notice the three join options.

SELECT OO.OHEADNotes FROM OOHEADNOTES as OO
INNER JOIN BASE as B ON ( OO.OATXID=B.OATXID or OO.OAPOTX=B.OAPOTX or OO.OAPRTX=B.OAPRTX )

Even if the SQL doesn't fit, can you give me an example of how to write the above SQL in the formula editor.
One other issue, in the book "Crystal Reports XI Official Guide" p.271 mentions to "Right-Click the SQL Expressions item in the Field Explorer and select 'New' from the dropdown"...
My problem is- I am also using CRXI ver.2, but I have no 'SQL Expression' in my Field Explorer.
Thanks
ReportExample.png
TableDefinitions.png
0
 
LVL 101

Accepted Solution

by:
mlmcc earned 500 total points
ID: 35143328
SQL Expressions only work with SQL databases and only if you are using the tables directly.  If you are using a COmmand then you can't use a SQL expression.

Also a SQL Expression can only return 1 value so I don't think it would do what you want.

Did you try that SQL in the COMMAND?
What was the problem?

The SQL you provided was much different.

Is the issue trying to join the 2 select statements?

mlmcc
0
 

Author Closing Comment

by:leason2
ID: 35143754
Good Call. I am taking your opinion and redoing the SQL. I just did a Recursive SQL statement to 'pivot' all the rows of Notes into one row. Thank you for the solution though!
0

Featured Post

Monthly Recap

May was a big month for new releases from Linux Academy! Take a look at what our team built recently in our blog. You can access the newest releases from our blog.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There have always been a lot of questions related to when Crystal Reports evaluates report components (such as formulas, summaries, cross-tabs, charts, to name a few examples). Crystal Reports uses a two-pass reporting process to provide greater …
Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question