The below SQL query is being run on SQL Server 2005/2008 using linked SQL (Oracle) and I get an error.
Declare @PriorMonth_StartDate Datetime
Declare @PriorMonth_EndDate Datetime
Set @PriorMonth_StartDate = '2012-03-01'
Set @PriorMonth_EndDate = '2013-10-31'
EXEC('
SELECT *
INTO #C_INFO
FROM OPENQUERY(ORACLE_CMIDW1,''
SELECT A.CID, A.ANO, A.COMP_REVD_DATE, A.REVIEW_COMP_DATE,
A.ISSUE, B.ENT_ID, A.TYPE
FROM XXX B
INNER JOIN YYY A ON B.ANO = A.ANO WHERE A.REVIEW_COMP_DATE Between ''' +
@PriorMonth_StartDate + ''' And ''' + @PriorMonth_EndDate
+ ''' AND Not A.ISSUE = 110 AND A.TYPE = 1 and B.ENT_ID In (2,3)
'')')
Here is the error message:
Msg 102, Level 15, State 1, Line 9
Incorrect syntax near 'Mar'.
Question: There is any connection between the error message and the SQL query? It looks like SQL is reading the date as March 01 2013 or something. If that's the case, it doesn't work because Oracle has it in a different format.