I'm working on the following query on Sybase ASE 12.5.4:
select distinct t2.pay_method_number "Cnumber",
t1.order_number,
t4.ship_company_name,
t2.method_of_payment,
t5.amount 'GC Amt$'
from order_header t1, payment_header t2, shipping_detail t3, shipping_header t4, payment_detail t5
where t1.order_number = t2.order_number
and t1.order_number = t4.order_number
and t2.order_number=t5.order_number
and t2.payment_number=t5.payment_number
and t3.date_shipped >= dateadd(dd,-1,"11/15/11")
and t3.date_shipped < dateadd(dd,0,"11/15/11")
and t1.order_number=t3.order_number
and t1.source_key = "RNWHUMC"
and t1.order_status not in ("H", "SH", "DE")
and t2.method_of_payment = "GC"
and t1.customer_number != XXXXXX
when in this form it returns the proper record in 1 sec.
if I change the following from:
and t3.date_shipped >= dateadd(dd,-1,"11/15/11")
and make it:
and t3.date_shipped >= dateadd(dd,-1,getdate())
the query never returns. Show plan using the "11/15/11" show indexes being used on all the tables. When I change the date to getdate() the plan shows a table scan on a very large table. And it's not the t3 table, but the t1 table.
Any insight is greatly appreciated.
Eric