I'm not sure what you're trying to query but if you want to spool the result just start spool before your query and stop it in the end, like
Spool "Filepath"
With Sqltmp
as
(
Select Count(*) as cnt from employee where age is null and rownum<=2
)
Select
case
When cnt>0 Then
Select Empid from employee where rownum<=10;
Else
Select Empid from employee where rownum<=10;
End
From Sqltmp
Spool off;
However, what wont run properly since you have separate statements in case so perhaps you meant to do a scalar query. SOmething like
Spool "Filepath"
With Sqltmp
as
(
Select Count(*) as cnt from employee where age is null and rownum<=2
)
Select
case
When cnt<0 Then
(Select Empid from employee where rownum<=10)
Else
(Select Empid from employee where rownum<=10)
End
From Sqltmp
Spool off;
However I still don't understand why the select is the same in both case branches and why you select only 2 rows in the WITH clause...