views:

680

answers:

3

I have a SQL Server 2005 that has a 'Linked Server' to another SQL Server 2005.

When I run a simple query on one of the tables against the linked server:

SELECT    TOP 10 [Pat_Id]
FROM   [Prod].[PIS].[dbo].[W_PATIENT]

This error occurs:

Msg 8114, Level 16, State 8, Line 1
Error converting data type DBTYPE_DBTIMESTAMP to datetime.
Msg 8114, Level 16, State 8, Line 1
Error converting data type DBTYPE_DBTIMESTAMP to datetime.

However, when I use OPENQUERY it works:

SELECT * FROM OPENQUERY([Prod], 'SELECT TOP 10 [Pat_Id] FROM [PIS].[dbo].[W_PATIENT]')

The W_PATIENT table does not have any 'TIMESTAMP' typed fields. It does have 5 DATETIME fields.

It is also import to note that I can query other tables with DATETIME values without an problem. The problem is focused on the W_PATIENT table.

A: 

Are you sure your linked server is set up correctly? What does this query yield:

SELECT product, provider FROM sys.servers WHERE name = 'Prod';
Aaron Bertrand
I believe I have setup the linked server correctly, because I am able to query other tables in the same database on the linked server.Here is the result of the query.product provider----------- ---------SQL Server SQLNCLI
jacksonakj
And you're sure W_Patient is a table, and not a view?
Aaron Bertrand
A: 

Is it possible that some of those DATETIME fields have "wrong entries", out of range etc. For example if one of those is actually a string with some "garbage" inside? Open query is executed on the remote server and only results are returned; while with select, data is transferred over so data-conversion is applied.

I would consider some data-profiling on the w_patient table. If you have SQL server 2008, there is a data profiling task in SSIS, but you can also find other tools to check for data quality.

Damir Sudarevic
It seems you are on the right track. Based on your comment I tried to query each DATETIME field and validate the value as a date. I used this query: SELECT * FROM [dbo].[W_PATIENT] WHERE ISDATE((CONVERT(NVARCHAR(25),[DOB],100))) = 0 AND NOT [DOB] IS NULL; I wish I had SQL Server 2008 to help with the data-profiling. Any suggestions for another tool?
jacksonakj
If the linked server is SQL Server and also uses DATETIME then I don't see how there can be "wrong entries" unless there is some kind of bug that allowed the bad data in there, or if in fact the "table" on the other end is a view that is trying to pull data from some other type of database. The DBTYPE_DBTIMESTAMP reference indicates some driver or some interpretation of the data type *outside of SQL Server* is interfering here.
Aaron Bertrand
You can tryhttp://datacleaner.eobjects.org/it is java so you'll need JDBC driver toohttp://msdn.microsoft.com/en-us/data/aa937724.aspx
Damir Sudarevic
@Aaron, that may be true too; my guess is simply that optimizer decided not to execute query on remote machine, but is transferring rows over to be filtered on the local server -- junk included.
Damir Sudarevic
@Damir, DataCleaner was a huge help. I ended up finding some rows with bad values.
jacksonakj
A: 

jacksonakj,

I experienced similar problem today. Have been picking records from an Oracle database using a linked server for the past 1 year. Suddenly today (10 Aug 2010), I started getting the same error - error Converting data type DBTYPE_DBTIMESTAMP. I followed the use of OPENQUERY and IT WORKED. Thanks a million.

Rogoneeze