December 13, 2002 at 10:01 am
Guys,
I need some help with parameters - I need to retrieve records between @startRow and @EndRow and sort these columns by @SortColumn with the sort type(@SortType) as Asc or Desc
ex
Select col1, col2,..
FROM tablename
WHERE COL BETWEEN @STARTROW AND @ENDROW
ORDER BY @SORTCOLUMN @SORTTYPE
Help is appreciated
December 13, 2002 at 12:13 pm
I think simplest to use some dynamic sql here - use exec (@sql) where @sql represents a built string from your input params.
eg,
set @sql = 'Select col1, col2,..
FROM tablename
WHERE COL BETWEEN '+@STARTROW+' AND '+@ENDROW+ '
ORDER BY ' + @SORTCOLUMN +' '+@SORTTYPE
exec sp_executesql @sql
You'll need to make sure the parameters are converted to strings first.
HTH.
Edited by - sunshinekid on 12/13/2002 12:21:10 PM
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply