Solved

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

Posted on 2009-05-12
10
2,430 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
  • 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
 
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
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

757 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now