Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linked SQL Server has error with converting data type DBTYPE_DBTIMESTAMP

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.

like image 696
jacksonakj Avatar asked Nov 18 '09 21:11

jacksonakj


1 Answers

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.

like image 177
Damir Sudarevic Avatar answered Sep 30 '22 19:09

Damir Sudarevic