Hi,
Try sequencing your select query result.
Check this code,
WITH NumberedMyTable AS
(
SELECT
Id,
Value,
ROW_NUMBER() OVER (ORDER BY Id) AS RowNumber
FROM
MyTable
)
SELECT
Id,
Value
FROM
NumberedMyTable
WHERE
RowNumber BETWEEN @From AND @To
Also, Your condition checks..
WHERE
Regno NOT IN
(
SELECT TOP 0
Regno RegNo,
PatientName,
The select here should have only Regno in the query.
Hope this helps.