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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2005

From novice to tech pro — start learning today.