I have been working on trying to create a SP that allows me to get a subset of results without too much expense on the server. This is what I have come up with so far. Anyone got any idea, comments or critiques?Also does anyone have a tutorial on profiling this query? I can't figuire out how to use the profiler :(USE cahootingDECLARE @First_id int, @StartRow intDECLARE @PageNo int, @maximumRows intDECLaRE @ItemName varchar(128)DECLARE @Region int , @AddedOn datetime DECLARE @OField varchar(15), @Key bigintSET @OField = 'ItemName'SET @PageNo=5SET @maximumRows=50Set @PageNo = (@PageNo * @maximumRows) - (@MaximumRows - 1)/* Get first row from pageNo */SET ROWCOUNT @PageNo SELECT @Region=RegionID,@ItemName = ItemName,@AddedOn = AddedOn FROM DirectoryItems ORDER BY CASE WHEN @OField = 'RegionID' THEN RegionID WHEN @OField = 'AddedOn' THEN AddedOn END, CASE WHEN @OField = 'ItemName' THEN ItemName END/* To Get the dynamic where we need to set to null the fields that we are not using */IF @OField = 'RegionID' BEGIN SET @ItemName = null SET @AddedOn = null ENDELSE IF @OField = 'AddedOn' BEGIN SET @ItemName = null SET @Region = null ENDELSE IF @OField = 'ItemName' BEGIN SET @AddedOn = null SET @Region = null END/* Actually retrieve rows */SET ROWCOUNT @maximumRows SELECT * FROM DirectoryItems WHERE ItemName >= COALESCE(@ItemName,ItemName) AND RegionID >= COALESCE(@Region,RegionID) AND AddedOn >= COALESCE(@AddedOn,AddedOn) ORDER BY CASE WHEN @OField = 'RegionID' THEN RegionID WHEN @OField = 'AddedOn' THEN AddedOn END, CASE WHEN @OField = 'ItemName' THEN ItemName ENDSET ROWCOUNT 0GO