Subject | RE: [firebird-support] Group By SQL - Give Blank a "Title" |
---|---|
Author | Alan McDonald |
Post date | 2004-10-08T04:46:42Z |
> >I'm running a simple group by query that returns the name of the groupand there could be NULLS *and* blanks
> >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
Alan