Solved

"unexpected NULL value" for Linked Server select statement (MS SQL 2005 to MYSQL 4.?)

Posted on 2009-05-12
10
2,670 Views
Last Modified: 2012-08-13
Msg 7342, Level 16, State 1, Line 1
An unexpected NULL value was returned for column "[ServerName]...[TableName].collDate" from OLE DB provider "MSDASQL" for linked server "ServerName". This column cannot be NULL.

I have a linked server setup on MS SQL 2005 to MYSQL 4.? (Vendor's db). I cannot change settings on the MYSQL vendor machine. I CAN successfully query all fields in table except for the one named "colldate":

Select colldate from LinkedServerName...TableName

the simple select statement above retuns the following error mesasage:
"An unexpected NULL value was returned for column "[LinkedServerName]...[TableName].collDate" from OLE DB provider "MSDASQL" for linked server "LinkedServerName". This column cannot be NULL."

I hope this is an easy one. Thanks in advance.
Select colldate from ServerName...TableName

Open in new window

0
Comment
Question by:DOHMH
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
10 Comments
 
LVL 41

Expert Comment

by:ralmada
ID: 24369177
0
 

Author Comment

by:DOHMH
ID: 24369722
I was working with that link prior to submitting my question but still could not get it to work.

I've tried:
SELECT * FROM OPENQUERY (LinkedServer,
'SELECT colldate FROM tablename
where colldate IS NOT NULL')  

Same Message

I also tried:
SELECT cast(case when colldate like '' then null else collDate end as datetime)
FROM LinkedServer...tablename

Same Message

I know there are blanks in that field but also real dates...
0
 
LVL 41

Expert Comment

by:ralmada
ID: 24376243
what about
SELECT * FROM OPENQUERY (LinkedServer,
'SELECT CASE colldate <> '' then colldate else '1/1/1900' end as yourdate FROM tablename')  
 
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 41

Expert Comment

by:ralmada
ID: 24376254
oops, missed some quotes
SELECT * FROM OPENQUERY (LinkedServer,
'SELECT CASE colldate <> '''' then colldate else ''1/1/1900'' end as yourdate FROM tablename')  
0
 

Author Comment

by:DOHMH
ID: 24376521
Syntax error - I've tried playing around with the quotes and syntax but still no dice.
0
 
LVL 41

Expert Comment

by:ralmada
ID: 24377355
please note that I'm using two consecutive single quotes( ' ) around the date, not one double quote.

SELECT * FROM OPENQUERY (LinkedServer,
'SELECT COALESCE(colldate, ''1/1/1900'') as yourdate FROM tablename')  
0
 

Author Comment

by:DOHMH
ID: 24379018
Your query does get me a result (which is a good sign) but all returned records give me data like the following in the "yourdate" column: 0x303030302D30302D3030
0
 

Author Comment

by:DOHMH
ID: 24379255
Looks like I can cast the field to char if I use this...

SELECT * FROM OPENQUERY (ServerName,
'SELECT cast(COALESCE(colldate, ''1/1/1900'') as char(10))as yourdate FROM tablename')  

but the data comes out in the 0000-00-00 format - as a matter of fact, I see many 0000-00-00 entries but no 1900-01-01 entries. I have to see what's going on, if anything with 1/1/1900 in the syntax. But thank you for the help in getting here. I'll give you the points for this.
0
 
LVL 41

Accepted Solution

by:
ralmada earned 500 total points
ID: 24381775
And what about this?
SELECT * FROM OPENQUERY (ServerName,
'SELECT cast(COALESCE(colldate, ''1900-01-01'') as char(10)) as yourdate FROM tablename')  
Although I understand that MySQL allows you to enter a "dummy" date, i.e. '0000-00-00' instead of NULL so why not just like this?
SELECT * FROM OPENQUERY (ServerName,
'SELECT cast(colldate as char(10)) as yourdate FROM tablename')  
 
 

 
0
 

Author Closing Comment

by:DOHMH
ID: 31580685
Thanks for all the help.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question