Solved

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

Posted on 2009-05-12
10
2,560 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
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 
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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MySQL - Restore Database SQL File 5 53
create insert script based on records in a table 4 21
Create a MySQL table as easily as possible 6 36
SQL Error - Query 6 25
Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

770 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