I have created a procedure for the purpose of fetching the yesterday data from an Oracle database table and insert it into a SQL Server 2012 table.
Using the following
IF OBJECT_ID('tempdb..#Temp') IS NOT NULL
DROP TABLE #Temp
SELECT
LEAD(CONVERT(VARCHAR, CONVERT(DATETIME, '01-JAN-1970 03:00:00', 120) + [DAT_CLOSEDATE] / (24 * 60 * 60), 120), 1, CONVERT(VARCHAR, CONVERT(DATETIME, '01-JAN-1970 03:00:00', 120) + [DAT_CLOSEDATE] / (24 * 60 * 60), 120)) OVER (PARTITION BY [TXT_TICKETNUMBER] ORDER BY [DAT_CLOSEDATE]) AS [CLOSE_DATE]
INTO #Temp
FROM OPENQUERY(ORACLE_DB, 'SELECT DAT_CLOSEDATE ,TXT_TICKETNUMBER
FROM SCHEME.TABLE')
WHERE
[DAT_CLOSEDATE] = DATEADD(d, -1, GETDATE())
SELECT * FROM #Temp
Everything is working as expected when I don't use the WHERE condition.
But once I use the WHERE condition, the following error appears
Msg 8115, Level 16, State 2, Line 4
Arithmetic overflow error converting expression to data type datetime.
NOTE:
The DAT_CLOSEDATE column datatype in the Oracle table is float and its datetime in sql server .
I used the LEAD and CONVERT functions in order to convert its values to be a datetime datatype
I have tried to convert it to date datatype as following.
IF OBJECT_ID('tempdb..#Temp') IS NOT NULL
DROP TABLE #Temp
SELECT
lead(convert(varchar,convert(date,'01-JAN-1970 03:00:00',120) +
[DAT_CLOSEDATE]/(24*60*60), 120),1,convert(varchar,convert(date,'01-JAN-
1970 03:00:00',120) + [DAT_CLOSEDATE]/(24*60*60), 120)) over(partition by
[TXT_TICKETNUMBER] order by [DAT_CLOSEDATE])AS [CLOSE_DATE]
INTO #Temp
FROM OPENQUERY(ORACLE_DB, 'SELECT DAT_CLOSEDATE ,TXT_TICKETNUMBER
FROM SCHEME.TABLE')
WHERE [DAT_CLOSEDATE] = DATEADD(d,-1,GETDATE())
SELECT * FROM #Temp
But I got this error
Msg 206, Level 16, State 2, Line 4
Operand type clash: date is incompatible with float
sample data for DAT_CLOSEDTE column in the oracle table which is FLOAT
DAT_CLOSEDATE
1531038410
1531038433
1531038438
1531038447
1531038449
1531038450
1531038506
1531038506
One of the resolution am looking for is I expect OPENQUERY syntax to be something like the following:
OPENQUERY(ORACLE_DB, 'SELECT DAT_CLOSEDATE, TXT_TICKETNUMBER
FROM SCHEME.TABLE
WHERE [DAT_CLOSEDATE] = trunc(sysdate)-1')
but it needs to be converted from FLOAT to DATE data type first.
float? Both Oracle and SQL Server and date and time datatypes.