English 中文(简体)
具有活力的教职 按条款计算,2008年8月服务器出现错误
原标题:Dynamic Query with Order By clause arises an error in SQL Server 2008

我有一个充满活力的处决问题。 在这种询问中,我从用户那里获得一些参数(例如,计算参数)。 因此,我使用<代码>sp_executesql进行查询。 当我具体说明order by within the query时,我收到一个错误的信息:<>>。 除非另有说明,否则按条款分列的书面记录在意见、在线功能、衍生表格、子类和共同表格表述中无效。 我怎么能够来处理这个问题


SET @sql = SELECT * FROM (SELECT ROW_NUMBER() OVER(ORDER BY CaseID)AS RowNumber ,*
FROM [dbo].[CV_CaseMaster] WHERE SpaceID = @SID
order by @OrderBy ) AS CV_CaseMasterDetails WHERE RowNumber BETWEEN @MinRow AND @MaxRow

......


EXEC sp_executesql @sql
                  ,N @SID UNIQUEIDENTIFIER,@MinRow int, @MaxRow int,@OrderBy VARCHAR(50) 
                  ,@SID=@SpaceID,@MinRow = @CurrentMinRow,@MaxRow = @CurrentMaxRow, @OrderBy =  @SortBy......

<>>>>

我能否在<条码>栏目中具体规定<条码>。

最佳回答

你在询问中把命令放在错误的位置上,你不能用一个参数来命令。

我对这项工作持怀疑态度,但让你投了反对票。

SET @sql =  SELECT * 
            FROM (SELECT ROW_NUMBER() OVER(ORDER BY CaseID) AS RowNumber ,*
                  FROM [dbo].[CV_CaseMaster] 
                  WHERE SpaceID = @SID ) AS CV_CaseMasterDetails 
            WHERE RowNumber BETWEEN @MinRow AND @MaxRow 
            ORDER BY  +@SortBy
问题回答

暂无回答




相关问题
Performance impact of indexed view in MS SQL Server 2008

Does anyone have experience with using indexed view in MS SQL Server 2008? I am trying to find out how does indexed view affect performance of insert / update statements, that are adding / updating ...

Lock Escalation - What s happening here?

While altering a table (removing a column) in SQL Server 2008, I clicked the Generate Change Script button and I noticed that the change script it generated drops the column, says "go" and then runs ...

Round to nearest 5 in SQL Server

I have a Money column in my SQL Server 2008 table. In my below query how can I round it to nearest 5$ select FineAmount from tickets Thanks