Hi Christoph,
I'm not sure what you're trying to do here. Could you explain it? I think we could help better.
But you need to be very careful here - there is no good way to do this without dynamic SQL like YS wrote, and that is both slow, because it is dynamic SQL and also the COUNT(*), which is slow, and open to security problems like SQL injection.
Regards,
John