converting data type DBTYPE_DBDATE to datetime.

I am using sql server 2005 to connect to a Linked Server (DB2 database, I'm fairly sure, but not a 100%)
using the following query
SELECT  * FROM OPENQUERY
 ( US_DATABASE ,
'SELECT CHANGE_ID,LOCATION_ID,REQUESTER_ID,
REQUEST_DATE
FROM US.Change LINKEDTABLE
 '
)

I get an error message
Error converting data type DBTYPE_DBDATE to datetime.

when I include the "REQUEST_DATE" in the query,  otherwise it returns the result set fine...

Can I CAST the REQUEST_DATE to  a string or some other datatype to get around this issue?

any help appreciated, thanks
blossomparkAsked:
Who is Participating?
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
yes, you do 2 explicit casts:

[SELECT CHANGE_ID, LOCATION_ID, REQUEST_ID, CONVERT(DATETIME, REQUEST_DATE, 120)
 FROM OPENQUERY
 ( US_DATABASE ,
'SELECT CHANGE_ID,LOCATION_ID,REQUESTER_ID,
TO_CHAR(REQUEST_DATE, ''YYYY-MM-DD HH24:MI:SS'' ) REQUEST_DATE
FROM US.Change LINKEDTABLE
 '
) 

Open in new window


see also:
http://www.experts-exchange.com/A_1499.html
0
 
blossomparkAuthor Commented:
Hi Angellll
thanks for your response,
getting the following error returned

[OLE/DB provider returned message: [IBM][CLI Driver][DB2/6000] SQL0440N
 No authorized routine named "TO_CHAR" of type "FUNCTION" having compatible arguments was found.
  SQLSTATE=42884
]
OLE DB error trace [OLE/DB Provider 'MSDASQL' ICommandPrepare::Prepare returned 0x80004005:   ].
Msg 7399, Level 16, State 1, Line 1
OLE DB provider 'MSDASQL' reported an error.  
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
I am no DB2 specialist, so please check what format you can put into TO_CHAR for date formats, so it returns a string in the formst YYYY-MM-DD hh24:mi:ss like oracle does ... as this is the format need to the convert(112) style in sql server.
0
 
momi_sabagCommented:
it depends on which db2 you are using
to_date is oracle syntax so it is only supported in recent versions and not on all platforms

just try either
cast (request_date as varchar)
or
char(request_date)
0
 
blossomparkAuthor Commented:
Hi Angellll and momi sabag....some of the data in the source table is corrupt which has complicated the issue....i will close this for now and use your suggestions when the source table is cleaned...
thanks for your help
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.