Declare variable for SELECT statement in Postgres function
If the SELECT with the CASE expression is something you want to return in the output table, just add RETURN QUERY before it:

RETURN QUERY SELECT CASE ...


Note: 8.4 is very old now.  Even 9.0 is out of support by now - consider upgrading to a recent major version soon.  The old ones usually don't get any security (and other) fixes anymore.