CREATE PROCEDURE [dbo].[spGetPollSubjectsPaging] 
	@PageSize INT , 
	@CurrentPage INT
AS
BEGIN
	SELECT * FROM  tblPollSubject
	WHERE subject_id IN
	(SELECT TOP (@PageSize) s.subject_id
	FROM tblPollSubject s
	LEFT JOIN tblPollOption o ON (o.subject_id = s.subject_id)
	WHERE s.subject_id NOT IN 
	(SELECT TOP ((@CurrentPage - 1) * @PageSize) ExcludedRange.subject_id
	FROM tblPollSubject ExcludedRange 
	LEFT JOIN tblPollOption ON (tblPollOption.subject_id = ExcludedRange.subject_id)
	GROUP BY ExcludedRange.subject_id
	HAVING COUNT(tblPollOption.option_id) > 0
	ORDER BY ExcludedRange.subject_id) 
	GROUP BY s.subject_id
	HAVING COUNT(o.option_id) > 0
	ORDER BY s.subject_id);
END
		