开发者

How do I exclude null rows without excluding null cells when pulling Excel into C# using SQL (ADO)?

I have a query like the following:

SELECT * FROM OPENROWSET('MS开发者_Go百科DASQL', 'Driver={Microsoft Excel Driver (*.xls)};DBQ=D:\test.xls','SELECT * FROM Sheet1$]')

This brings back rows that are all null if they were ever edited and then deleted. I want to exclude those, but still include rows that have good data but possible null cells.

My first instinct was to do a "WHERE each column IS NOT NULL" ANDed together, like so:

SELECT * FROM OPENROWSET('MSDASQL', 'Driver={Microsoft Excel Driver (*.xls)};   DBQ=D:\test.xls', 'SELECT * FROM Sheet1$]')
WHERE 
(
  Col1 IS NOT NULL 
  AND Col2 IS NOT NULL 
  AND Col3 IS NOT NULL 
  AND Col4 IS NOT NULL 
)

This effectively eliminates the null rows, but for some reason, also eliminates a row where Col4 had a null entry. I tried this with and without parens around the WHERE clause.

Does anyone see what I might be doing wrong, or in lieu of that, have a suggestion of a different method I can use to achieve the same results?

This is currently being implemented in C# using ADO, but I am testing the query using Sql Server Management Studio 2008.


WHERE 
(
  Col1 IS NOT NULL 
  OR Col2 IS NOT NULL 
  OR Col3 IS NOT NULL 
  OR Col4 IS NOT NULL 
)

or

WHERE Coalesce(Col1,Col2,Col3,Col4) IS NOT NULL (no coalesce function for oledb/excel)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜