Subject RE: [firebird-support] Group By SQL - Give Blank a "Title"
Author Alan McDonald
> >I'm running a simple group by query that returns the name of the group
> >and a count. One of the "groups" is a blank. Instead of just having a
> >blank, I want to say "No Value Specified".
> >
> >How can I accomplish this with SQL?
>
> select
> case groupname
> when '' then 'No Value Specified'
> else groupname
> end
> as group_name,
> count (*)
> from groupz
> group by 1;
>
> If the groupname column is smaller than the length of your
> literal string,
> you will also have to cast:
>
> select
> case groupname
> when '' then 'No Value Specified'
> else cast(groupname as varchar(18))
> end
> as group_name,
> count (*)
> from groupz
> group by 1;
>
> If your "blank" is really a null, then you can use coalesce instead.
>
> ./h

and there could be NULLS *and* blanks
Alan