Manivel
Manivel

Reputation: 39

how to select values from sqlserver2008 except null values?

I have a table called User_info. In which some columns contains values and some columns contains null values. How can I select value fields alone?

Upvotes: 0

Views: 389

Answers (1)

Tim Schmelter
Tim Schmelter

Reputation: 460340

From your comment:

In my case I want to select all the values from the table and need to bind the values to the corresponding fields again in the form. while binding, if a column contain null value then it raising an error. The error is

Conversion from type 'DBNull' to type 'String' is not valid

Then you either have to show the code that causes the invalid cast or replace nulls with an empty string:

SELECT Col1 = COALESCE(Col1,'') 
FROM User_info u 

Instead of COALESCE you could just as well use ISNULL.

Upvotes: 1

Related Questions