This doesnt work:
ALTER PROCEDURE [dbo].[dealership_Inventory_PagedAndSorted]
(
@sortExpression nvarchar(100),
@startRowIndex int,
@maximumRows int
)
AS
IF LEN(@sortExpression) = 0
SET @sortExpression = 'InventoryYear'
DECLARE @sql nvarchar (4000)
SET @sql = 'SELECT dealership_Inventory.Inventory_ID, InventoryYear, ImageLocation
FROM (SELECT dealership_Inventory.Inventory_ID, InventoryYear, ImageLocation,
ROW_NUMBER() OVER (ORDER BY ' + @sortExpression + ') AS RowRank
FROM dealership_Inventory
INNER JOIN dealership_InventoryImages
ON (dealership_Inventory.Inventory_ID = dealership_InventoryImages.Inventory_ID)
) AS ModelsWithRowNumbers
WHERE RowRank >' + CONVERT(nvarchar(10), @startRowIndex) +
' AND RowRank <= (' + CONVERT(nvarchar(10), @startRowIndex) + ' + '
+ CONVERT(nvarchar(10), @maximumRows) + ')'
EXEC sp_executesql @sql
|