我正在使用 SQL Server 2008。我的程序是
SELECT ContractorID ,
Name,
ROW_NUMBER() OVER (ORDER BY ContractorID) as RowNumber
FROM dbo.Contractor
这是可行的,但现在我想将参数传递给OVER
函数。
我努力了 :
DECLARE @OrderBy VARCHAR(MAX)
SET @OrderBy = 'ORDER BY ContractorID'
SELECT ContractorID ,
Name,
ROW_NUMBER() OVER (@OrderBy) as RowNumber
FROM dbo.Contractor
这会给出错误“@OrderBy 附近的语法不正确”?我怎样才能做到这一点?谢谢。