MyNeckHurts
Programmer
I've written the following pass thru query to a SQL database. I need to pull data from 3 days ago. The SQL date field is a datetime field and the query is pulling way too many records. Is there a way to convert the date in the pass thru query?
SELECT a.TXN_DT as date, a.ORD_NBR as ordno, a.ORD_LIN, a.PLANT_ID as DC, a.SKU, a.TXN_QTY as Quantity, a.TXN_CD as TxCde, a.CUST_ID as Cstno, a.CUST_SFX_CD as Suffix, a.CUST_ORD_NBR as CustPO, a.COMMENT1, a.COMMENT2, a.CUST_NM as cstname, a.SHIPTO_ADDR1 as addr1, a.SHIPTO_ADDR2 as addr2, a.SHIPTO_ADDR4 as city, a.SHIPTO_STATE_CD as state, a.SHIPTO_ZIP_CD as Zip, a.CUST_CLASS_CD as Class, a.CUST_TYPE_CD as Type, b.ORD_NBR_ORG as OrgOrdNum, b.ORD_LIN_ORG as OrgPrdLin, b.RMA_RSN_CD as RMAReasonCode
FROM Returnsdly a, ASI_COPS_ORD_DETAIL b
WHERE
a.ORD_NBR = b.ORD_NBR
AND a.ORD_LIN = b.ORD_LIN
and a.txn_dt >= getdate()-3
and a.plant_id = 'SCS'
or (a.plant_id = 'SDF'
or a.plant_id = 'NOL'
or a.plant_id = 'RTNS'
or a.plant_id = 'WMDC'
or a.plant_id = 'LSPCS')
and a.prod_ctgy = 'CP'
Thanks!
SELECT a.TXN_DT as date, a.ORD_NBR as ordno, a.ORD_LIN, a.PLANT_ID as DC, a.SKU, a.TXN_QTY as Quantity, a.TXN_CD as TxCde, a.CUST_ID as Cstno, a.CUST_SFX_CD as Suffix, a.CUST_ORD_NBR as CustPO, a.COMMENT1, a.COMMENT2, a.CUST_NM as cstname, a.SHIPTO_ADDR1 as addr1, a.SHIPTO_ADDR2 as addr2, a.SHIPTO_ADDR4 as city, a.SHIPTO_STATE_CD as state, a.SHIPTO_ZIP_CD as Zip, a.CUST_CLASS_CD as Class, a.CUST_TYPE_CD as Type, b.ORD_NBR_ORG as OrgOrdNum, b.ORD_LIN_ORG as OrgPrdLin, b.RMA_RSN_CD as RMAReasonCode
FROM Returnsdly a, ASI_COPS_ORD_DETAIL b
WHERE
a.ORD_NBR = b.ORD_NBR
AND a.ORD_LIN = b.ORD_LIN
and a.txn_dt >= getdate()-3
and a.plant_id = 'SCS'
or (a.plant_id = 'SDF'
or a.plant_id = 'NOL'
or a.plant_id = 'RTNS'
or a.plant_id = 'WMDC'
or a.plant_id = 'LSPCS')
and a.prod_ctgy = 'CP'
Thanks!