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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Inner Select Need Parameters 1

Status
Not open for further replies.

Ascalonian

Programmer
Jan 4, 2008
264
0
0
US
I have a SQL statement structured similar to:

Code:
SELECT oh.header_id,
       ol.line_id,
       ol.line_number
  FROM order_headers oh,
       order_lines ol
 WHERE oh.header_id IN (SELECT x.header_id
                          FROM some_table x
                         WHERE ordered_date = SYSDATE)
   AND ol.header_id = oh.header_id

All fine and dandy. However, what if I want to use the above SQL in a report and want to change the SYSDATE to another date the user chooses? Is there a way in SQL to do this? I know that the inner-select knows nothing about the oh or ol, which means I can't set a date somewhere else and have the inner select recognize it like:
Code:
SELECT oh.header_id,
       ol.line_id,
       ol.line_number
  FROM order_headers oh,
       order_lines ol
 WHERE oh.header_id IN (SELECT x.header_id
                          FROM some_table x
                         WHERE ordered_date = oh.some_date)
   AND ol.header_id = oh.header_id

Again, I appreciate the help.
 
Code:
SELECT oh.header_id,
       ol.line_id,
       ol.line_number
  FROM order_headers oh,
       order_lines ol
 WHERE exists (SELECT 1
                          FROM some_table x
                         WHERE ordered_date = oh.some_date
                               and oh.header_id = x.header_id
)
   AND ol.header_id = oh.header_id

-----------------------------------------
I cannot be bought. Find leasing information at
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top