Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Replacing Nulls

Status
Not open for further replies.
Joined
Sep 24, 2003
Messages
34
Location
US
Hi,,,,

I am trying to replace the Nulls with blanks in my query output. Does any1 know how?
 
CHAR and VARCHAR fields can use ISNULL(column_name, value_for_nulls)
Code:
SELECT ISNULL(name_of_somethng, ' ') AS "name_of_something"
FROM MyTable

With numbers it would be necessary to CAST the number as VARCHAR in order to use blanks in place of NULLS.
Code:
SELECT ISNULL(CAST(number_of_thngs AS VARCHAR), ' ') AS "number_of_things"
FROM MyTable

I think that will work. I am uncertain what the result of CASTing a NULL might be, having never done that. But I am pretty sure you wont be able to have an expression that sometimes evaluates to numbers and other times evaluates to a string.
 
here is another solution:

update dbo.mytable
set [ColwithNulls] = ''
where [ColWithNulls] is null
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top