on ‎2016 Nov 25 4:18 AM
I'm running a rather simple query from a v16.0.0.2344 database against a MS SQL Server 2012 R2 database - and to my surprise I get an empty result set although it should return rows.
The query contains a WHERE condition based on comparison with a datetime value, such as
select * from MyRemoteMsView
where datField >= '2016-07-01';
and should return several rows with a date value in the 2nd have of this year.
(It does not matter whether the datetime value is specified via a connection variable or as date literal).
Using CIS_OPTION = 7 I can trace that the statement is passed to the MS SQL Server in full passthrough mode, such as
select t1.* from "MyDatabase".dbo."MyView" t1
where t1."datField" >= '2016-07-01 00:00:00.000'
which looks ok.
However, the statement when directly executed on the MS SQL Server will fail because of our DATEFORMAT (*) setting there (default for German locale = "dmy"), so the query returns a 242 conversion error - basically telling that the varchar value is out of range for a datetime. When I issue "SET DATEFORMAT ymd" on MS SQL Server, the query returns the correct result set.
My questions:
(*): MS SQL Server's DATEFORMAT setting is comparable to SA's date_order option, but has no connection to SA's dateformat() function.
Request clarification before answering.
Jack wrote:
Is datField a timestamp column? Perhaps if you cast it to char, then the formatting will be left untouched.
Well, that seems to allow for a workaround at least: When I supply the comparison value as usual timestamp literal or as a timestamp variable and then convert the MS SQL Server datetime column to an international date format style (here 120 for ODBC canonical), the comparison is treated correctly:
select t1.* from "MyDatabase".dbo."MyView" t1 where convert(varchar(30), t1."datField", 120) >= '2016-07-01 00:00:00.000' order by t1."datField";
I'd consider that a workaround as casting a datetime value won't lead to a sargable condition and might perform bad with a huge table. But in my case, it's sufficient.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 15 | |
| 9 | |
| 6 | |
| 5 | |
| 4 | |
| 4 | |
| 3 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.