SET @SQL = 'SELECT FilePath
FROM (SELECT ROW_NUMBER() OVER(ORDER BY ID) AS Row, *
FROM tblFiles ) AS tbl WHERE Row >= '
+ CONVERT(varchar(9), @StartIdx) + ' AND
Row <= ' + CONVERT(varchar(9), @EndIdx) + ' AND FileName = img1'
Has a serious problem, the only file it will ever look for will be named "img1"
Where did you get his procedure? Cut, paste, and ask for us to fix it for you doesn't usually work well. Where, in fact, did
img1 even come from in order for you to select for it? Is it a table column? Specific value you chose but didn't declare? What?