I love the new DATE datatype in SQL Server 2008, but when I compare a DATE field to a DATETIME field on a linked server (SQL 2005, in this case), like this:
DECLARE @MyDate DATE
SET @MyDate = CONVERT(DATE, GETDATE())
SELECT *
FROM MySQL2005LinkedServer.SomeDB.dbo.SomeTable
WHERE SomeDatetimeField < @MyDate
I get this error:
OLE DB provider "SQLNCLI10" returned message "Unspecified error".
OLE DB provider "SQLNCLI10" returned message "The scale is invalid.".
"The scale is invalid" is obviously because the Native client is passing the DATE datatype back to the linked server, and since it s SQL 2005, it doesn t know what to do with it. Running this same query against a 2008 server works just fine - SQL Server is able to compare the DATE and DATETIME datatypes without a problem.
Here s my question - is there a reason that the Native Client doesn t automatically convert the DATE value of 2009-11-09 to a DATETIME of 2009-11-09 00:00:00.000 so that the previous version of SQL Server won t choke on it?