Solved

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

Posted on 2009-05-12
10
2,831 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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

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…
In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

615 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