I'm querying a DataBase via Excel ODBC.
I can compare the field with an hard-coded date in my Excel's ODBC query with :
BOMD.BOMENDDAT_0 > {ts '2018-05-05 00:00:00'}
But I can't seem to make a proper comparison with the present date :
BOMD.BOMENDDAT_0 > {ts SYSDATETIME()}
DATEDIFF(d, SYSDATETIME(), BOMD.BOMENDDAT_0) > 0
Any suggestion ?
I'm trying to build a query that select only records where the date of today is between :
BOMD.BOMSTRDAT_0
) BOMD.BOMENDDAT_0
) Those dates :
'26/02/2018 00:00:00'
'00/01/1900 00:00:00'
The whole query look like this :
SELECT BOMD.BOMQTY_0, BOMD.UPDDAT_0, BOMD.BOMSTRDAT_0, BOMD.BOMENDDAT_0
FROM myDB.BOMD BOMD
WHERE BOMD.UPDDAT_0 > {ts '2018-01-01 00:00:00'}
AND (
(BOMD.BOMSTRDAT_0 < {ts SYSDATETIME()})
OR BOMD.BOMSTRDAT_0 = 0
OR BOMD.BOMSTRDAT_0 is null
)
AND (
(BOMD.BOMENDDAT_0 > {ts SYSDATETIME()})
OR BOMD.BOMENDDAT_0 = 0
OR BOMD.BOMENDDAT_0 is null
)
{ts '2018-05-05 00:00:00'}
is used to convert string into datetime data type, you cannot use it on SYSDATETIME()
which is already a datetime (precisely datetime2) data type, just make it:
SELECT BOMD.BOMQTY_0, BOMD.UPDDAT_0, BOMD.BOMSTRDAT_0, BOMD.BOMENDDAT_0
FROM myDB.BOMD BOMD
WHERE BOMD.UPDDAT_0 > {ts '2018-01-01 00:00:00'}
AND (
(BOMD.BOMSTRDAT_0 < SYSDATETIME())
OR BOMD.BOMSTRDAT_0 = 0
OR BOMD.BOMSTRDAT_0 is null
)
AND (
(BOMD.BOMENDDAT_0 > SYSDATETIME())
OR BOMD.BOMENDDAT_0 = 0
OR BOMD.BOMENDDAT_0 is null
)
btw, your code will also return rows where both BOMENDDAT_0
and BOMSTRDAT
are zeros or nulls, is it really intended behaviour?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.