So you provide @n, being the number of users you want.
You provide @x being the percentage of those users who should have pictures.
select top (@n) *
from
(
select top (@n * @x / 100) *
from users
where picture is not null
union all
select top (@n) *
from users
where picture is null
) u
order by case when picture is not null then 1 else 2 end;
So... you want at most @n * @x / 100 users who have pictures, and the rest have to be people who don't have pictures. So I'm doing a 'union all' between my @n*@x/100 picture-people and enough others to complete my @n. Then I'm selecting them back, ordering my TOP to make sure that I keep the people who have a picture.
Rob
Edited: Actually, this would be better:
select top (@n) *
from
(
select top (@n * @x / 100) *, 0 as NoPicture
from users
where picture is not null
union all
select top (@n) *, 1 as NoPicture
from users
where picture is null
) u
order by NoPicture;
...because it removes the impact of the ORDER BY.