MikeAuz1979
Programmer
Hi,
Using SQL Server 2005 I'm trying to run an openquery statement that pulls data from an Oracle DB but with some date parameters and I'm getting a syntax error {Code Below}.
I would just use an oracle linked server using a T-sql statement but I'm getting errors with datetimes converting into SQL speak. (There's some future dates in Oracle like 03/03/3333 that is freaking SQL out.)
Anyone have any ideas?
Thanks for any help
Mike
Using SQL Server 2005 I'm trying to run an openquery statement that pulls data from an Oracle DB but with some date parameters and I'm getting a syntax error {Code Below}.
I would just use an oracle linked server using a T-sql statement but I'm getting errors with datetimes converting into SQL speak. (There's some future dates in Oracle like 03/03/3333 that is freaking SQL out.)
Anyone have any ideas?
Thanks for any help
Mike
Code:
DECLARE @SDATE DATETIME
DECLARE @EDATE DATETIME
DECLARE @SQLx VARCHAR(200)
Set @SDATE = '1 apr 2008'
Set @EDATE = '9 apr 2008'
Truncate Table BI_Datamart.tblCPMTemplatesRawExtract
Set @SQLx =
'select *
from OPENQUERY ( DWH_NAT_PR ,
'INSERT INTO tblCPMTemplatesRawExtract (item_desc,prefix,rng_code,ref_no,state_code,qty_sold)
SELECT ci.item_desc, stcu.prefix, rscu.rng_code,ci.ref_no,
stvtu.state_code,SUM (wsos.qty_sold)
FROM WW.CORP_ITEM ci,
WW.RNG_SCU rscu,
WW.ST_CONSUMER_UNIT stcu,
WW.ST_VNDR_TRD_UNIT stvtu,
WW.WKY_ST_OP_SLS wsos
WHERE ci.ref_no = rscu.ref_no
AND ci.ref_no = stcu.ref_no
AND rscu.state_code = wsos.state_code
AND rscu.div_no = wsos.div_no
AND rscu.ref_no = wsos.ref_no
AND stvtu.state_code = rscu.state_code
AND stvtu.ref_no = rscu.ref_no
AND stvtu.state_code = stcu.state_code
AND wsos.qty_sold > 10
AND wsos.week_end_date >= '''' + @SDATE + ''''
AND wsos.week_end_date <= '''' + @EDATE + ''''
AND stvtu.delist_date > sysdate
GROUP BY ci.item_desc,
stcu.prefix,
rscu.rng_code,
ci.ref_no,
stvtu.state_code
ORDER BY ci.item_desc ASC')'