Hi
You can easily fullfill your requirements like this.
Please try it out.
-- GetImages @RecordCount = NULL
CREATE PROCEDURE GetImages
@PageIndex INT = 1
,@PageSize INT = 10
,@RecordCount INT OUTPUT
AS
BEGIN
SET NOCOUNT ON;
SELECT ROW_NUMBER() OVER
(
ORDER BY emas.Id ASC
) RowNumber
,mimg.sphoto Photo
,CAST(emas.Id AS VARCHAR(10)) + '-' + emas.Name FullName
INTO #Results
FROM E_mas emas
INNER JOIN M_img mimg
ON emas.Id = mimg.Id
WHERE emas.Gender = 'F'
SELECT @RecordCount = COUNT(FullName)
FROM #Results
SELECT * FROM #Results
WHERE RowNumber BETWEEN(@PageIndex -1) * @PageSize + 1 AND(((@PageIndex -1) * @PageSize + 1) + @PageSize) - 1
DROP TABLE #Results
END
GO