SQLTeam.com | Weblogs | Forums

Forcing a Value when column is blank


#1

Hello
We have to submit a file to an external agency but one particular field
has to contain a value. The problem is, the field isn't always
containing data.

What I want to do is when there is data in the field to return that, 
but where the field is null I want it to force an arbitrary value of my 
choosing e.g 'No data to report'

I'm struggling with the syntax as I've been away from SQL for a while.

Can anyone advise please? Simplified I thought I could do a CASE 
query to say when field is null then 'No Data to report' ELSE select 
the data from the field and return that.

Thankyou

#2

Since you did not show your SQL statement...

Try using COALESCE(field, 'No Data to Report') if the field is string.


#3

can you try this.
select case when yourcoulumn is null then 'No data to report' else yourcolumn end from your table


#4

Thankyou to you both.

I went with the CASE and after some tweaking it works