当前位置: 代码迷 >> Sql Server >> 求详细解释。解决思路
  详细解决方案

求详细解释。解决思路

热度:81   发布时间:2016-04-27 12:40:10.0
求详细解释。
SQL code
    CREATE PROCEDURE [dbo].[Dv_GetRecordFromPage]@tableName   nvarchar(100),-- 表名@fldSort nvarchar(100) = 'dateandtime',-- 排序字段@pageSize int = 30,-- 每页大小 @page int = 1 ,-- 第几页@Sort bit = 1,-- 排序,@Sort=0 [email protected]=1 降序@ConditionStr nvarchar(1000),--查询条件@fldName nvarchar(2000) = '*'--查询字段ASDeclare @strTmp nvarchar(4000)Declare @sqlSort nvarchar(20)Declare @Compare varchar(1)Declare @Compare1 nvarchar(20)Declare @intCounts intDECLARE @var_Splitvalue varchar(5000)DECLARE @nRet intIf @Sort=0Begin   Set @sqlSort ='DESC'   Set @Compare = '<'   Set @Compare1='Min'   EndElse   Begin   Set @sqlSort ='ASC'   Set @Compare = '>'   Set @Compare1='Max'EndIf @page >1   begin    SELECT @intCounts=(@Page-1) * @pagesize    SET @strTmp='SELECT @var_Splitvalue [email protected]+'(' + @fldSort + ') FROM (Select Top '+CAST(@intCounts as nvarchar)+' ' + @fldSort + ' From [email protected]+' where [email protected]+' order BY ' + @fldSort + ' ' + @sqlSort+') as t'    EXEC sp_executesql @strTmp,[email protected]_Splitvalue varchar(5000) output',@var_Splitvalue output    SET ROWCOUNT @pagesize    SET @strTmp='SELECT '+ @fldName +' FROM [email protected]+' where '+ @ConditionStr +' AND ' + @fldSort+ @Compare + ' @2 '+' '+' ORDER BY ' + @fldSort + ' ' + @sqlSort    EXEC sp_executesql @strTmp,[email protected] varchar(5000)',@[email protected]_Splitvalue   EndElse   begin    SET ROWCOUNT @pagesize    SET @strTmp='SELECT '+ @fldName +' FROM [email protected]+' where ' [email protected]+' ORDER BY ' + @fldSort + ' ' + @sqlSort    EXEC sp_executesql @strTmp   end


------解决方案--------------------
说出你的问题,。。
------解决方案--------------------
很简单啊,你需要解释什么?

难道每一行都看不懂?
  相关解决方案