I am working in SQL Server 2008. I have a table with many columns that will not have values (at least, for the given situation). So, they will have a NULL value when I query each of them. I would like to instead make these NULL values be empty strings (i.e., ''). What is the best way to achieve this? My current idea is to set a DEFAULT value of '' on each them at the time that the table is created. However, since there are so many of them, this will be very tedious.
2 Answers
You have 2 options:
- As you said, give it a default value of empty string for columns you don't want to be null when you create table/add new columns.
- When you select nullable columns from the table you can use
IsNull(ColumnName,'')which means ifColumnNameisnullit'll return empty string ('').