Solved

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

Posted on 2009-05-12
10
2,610 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
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 
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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

839 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