Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple tables, one report

Status
Not open for further replies.

dbodenheimer

IS-IT--Management
Feb 7, 2003
1
US
Hi, I have a report that uses 2 tables for the results. Sounds simple right? well one of the tables stays the same, while the other changes. I would like to be able to pass the table name to the report and have the SQL statement change. Is there any way to do this?

Here is the SQL

Code:
SELECT
    PEPHR0303."LastName", PEPHR0303."FirstName", PEPHR0303."MI", PEPHR0303."SSN", PEPHR0303."DOB", PEPHR0303."HireCode", PEPHR0303."Region", PEPHR0303."PositionCode", PEPHR0303."HireType", PEPHR0303."HireDate",
    Wip."InquiryType", Wip."DateCompleted", Wip."hit", Wip."Info1", Wip."Info2", Wip."DontBill", Wip."CollectionDate"
FROM
    { oj "ops"."dbo"."?tbl" ?tbl INNER JOIN "ops"."dbo"."Wip" Wip ON          ?tbl."SSN" = Wip."SSN"}  
WHERE
    Wip."InquiryType" = 37 AND
    Wip."DontBill" = 0 AND
    Wip.&quot;Info1&quot; <> ''  
ORDER BY
    ?tbl.&quot;HireCode&quot; ASC,      ?tbl.&quot;Region&quot; ASC
 
are you using odbc connection? if you are, use CrystalReport1.SQLQuery = &quot;write your sql string here with the table name you like to pass&quot;

like this:
CrystalReport1.SQLQuery = &quot;SELECT
PEPHR0303.&quot;LastName&quot;, PEPHR0303.&quot;FirstName&quot;, PEPHR0303.&quot;MI&quot;, PEPHR0303.&quot;SSN&quot;, PEPHR0303.&quot;DOB&quot;, PEPHR0303.&quot;HireCode&quot;, PEPHR0303.&quot;Region&quot;, PEPHR0303.&quot;PositionCode&quot;, PEPHR0303.&quot;HireType&quot;, PEPHR0303.&quot;HireDate&quot;,
Wip.&quot;InquiryType&quot;, Wip.&quot;DateCompleted&quot;, Wip.&quot;hit&quot;, Wip.&quot;Info1&quot;, Wip.&quot;Info2&quot;, Wip.&quot;DontBill&quot;, Wip.&quot;CollectionDate&quot;
FROM
{ oj &quot;ops&quot;.&quot;dbo&quot;.&quot;mytable&quot; mytable INNER JOIN &quot;ops&quot;.&quot;dbo&quot;.&quot;Wip&quot; Wip ON mytable.&quot;SSN&quot; = Wip.&quot;SSN&quot;}
WHERE
Wip.&quot;InquiryType&quot; = 37 AND
Wip.&quot;DontBill&quot; = 0 AND
Wip.&quot;Info1&quot; <> ''
ORDER BY
mytable.&quot;HireCode&quot; ASC, mytable.&quot;Region&quot; ASC&quot;


i hope this helps.
 
You might use a stored procedure to do this.

The SP could then be passed a parameter which is used to construct dynamic SQL.

-k
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top