I have a SQL query I'm invoking via VB6 & ADO 2.8, that requires three
"Left Outer Joins" in order to return every transaction for a specific
set of criteria.
Using three "Left Outer Joins" slows the system down considerably.
I've tried creating a temp db, but I can't figure out how to execute
two select commands. (It throws the exception "The column prefix
'tempdb' does not match with a table name or alias name used in the
query.")
Looking for suggestions (and a lesson or two!) This is my first attempt
at SQL.
Current (working, albeit slowly) Query Below
TIA
SELECT
LEDGER_ENTRY.en try_amount,
LEDGER_TRANSACT ION.credit_card _exp_date,
LEDGER_ENTRY.en try_datetime,
LEDGER_ENTRY.em ployee_id,
LEDGER_ENTRY.vo ucher_explanati on,
LEDGER_ENTRY.ca rd_reader_used_ ind,
STAY.room_id,
GUEST.guest_las tname,
GUEST.guest_fir stname,
STAY.arrival_ti me,
STAY.departure_ time,
STAY.arrival_da te,
STAY.original_d eparture_date,
STAY.no_show_st atus,
STAY.cancellati on_date,
FOLIO.house_acc t_id,
FOLIO.group_cod e,
LEDGER_TRANSACT ION.original_re ceipt_id
FROM
mydb.dbo.LEDGER _ENTRY LEDGER_ENTRY,
mydb.dbo.LEDGER _TRANSACTION LEDGER_TRANSACT ION,
mydb.dbo.FOLIO FOLIO
LEFT OUTER JOIN
mydb.dbo.STAY_F OLIO STAY_FOLIO
ON
FOLIO.folio_id = STAY_FOLIO.foli o_id
LEFT OUTER JOIN
mydb.dbo.STAY STAY
ON
STAY_FOLIO.stay _id = STAY.stay_id
LEFT OUTER JOIN
mydb.dbo.GUEST GUEST
ON
FOLIO.guest_id = GUEST.guest_id
WHERE
LEDGER_ENTRY.tr ans_id = LEDGER_TRANSACT ION.trans_id
AND FOLIO.folio_id = LEDGER_TRANSACT ION.folio_id
AND LEDGER_ENTRY.pa yment_method='3 737******6100'
AND LEDGER_ENTRY.pr operty_id='abc1 23'
ORDER BY
LEDGER_ENTRY.en try_datetime DESC
"Left Outer Joins" in order to return every transaction for a specific
set of criteria.
Using three "Left Outer Joins" slows the system down considerably.
I've tried creating a temp db, but I can't figure out how to execute
two select commands. (It throws the exception "The column prefix
'tempdb' does not match with a table name or alias name used in the
query.")
Looking for suggestions (and a lesson or two!) This is my first attempt
at SQL.
Current (working, albeit slowly) Query Below
TIA
SELECT
LEDGER_ENTRY.en try_amount,
LEDGER_TRANSACT ION.credit_card _exp_date,
LEDGER_ENTRY.en try_datetime,
LEDGER_ENTRY.em ployee_id,
LEDGER_ENTRY.vo ucher_explanati on,
LEDGER_ENTRY.ca rd_reader_used_ ind,
STAY.room_id,
GUEST.guest_las tname,
GUEST.guest_fir stname,
STAY.arrival_ti me,
STAY.departure_ time,
STAY.arrival_da te,
STAY.original_d eparture_date,
STAY.no_show_st atus,
STAY.cancellati on_date,
FOLIO.house_acc t_id,
FOLIO.group_cod e,
LEDGER_TRANSACT ION.original_re ceipt_id
FROM
mydb.dbo.LEDGER _ENTRY LEDGER_ENTRY,
mydb.dbo.LEDGER _TRANSACTION LEDGER_TRANSACT ION,
mydb.dbo.FOLIO FOLIO
LEFT OUTER JOIN
mydb.dbo.STAY_F OLIO STAY_FOLIO
ON
FOLIO.folio_id = STAY_FOLIO.foli o_id
LEFT OUTER JOIN
mydb.dbo.STAY STAY
ON
STAY_FOLIO.stay _id = STAY.stay_id
LEFT OUTER JOIN
mydb.dbo.GUEST GUEST
ON
FOLIO.guest_id = GUEST.guest_id
WHERE
LEDGER_ENTRY.tr ans_id = LEDGER_TRANSACT ION.trans_id
AND FOLIO.folio_id = LEDGER_TRANSACT ION.folio_id
AND LEDGER_ENTRY.pa yment_method='3 737******6100'
AND LEDGER_ENTRY.pr operty_id='abc1 23'
ORDER BY
LEDGER_ENTRY.en try_datetime DESC
Comment