为了账号安全,请及时绑定邮箱和手机立即绑定

sql 执行分页 的where 条件 为字符串怎么处理?

sql 执行分页 的where 条件 为字符串怎么处理?

Zoe_z 2019-03-26 23:07:04
存储过程USE [Comom]GO/****** Object:  StoredProcedure [dbo].[Common_PageList]    Script Date: 03/26/2019 21:27:05 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOALTER PROCEDURE [dbo].[Common_PageList](@tab nvarchar(200),---表名@strFld nvarchar(max), --字段字符串@strWhere nvarchar(max), --where条件 @PageIndex int, --页码@PageSize int, --每页容纳的记录数@Sort nvarchar(255), --排序字段及规则,不用加order by@Total int output --总数)ASdeclare @strSql nvarchar(max)set nocount on;set @strSql=' SELECT * FROM (SELECT ROW_NUMBER()   OVER(ORDER BY ' + @Sort + ') AS rownum, ' + @strFld + ' FROM ' + @tab + ' where 1=1 ' + @strWhere + ') AS Dwhere  WHERE rownum BETWEEN ' + CAST(((@PageIndex-1)*@PageSize + 1) as nvarchar(20)) + ' and ' + cast((@PageIndex*@PageSize) as nvarchar(20))  exec (@strSql)  --print @strSql set @strSql='SELECT @Total = COUNT(0) FROM ' + @tab + ' WHERE 1=1 ' + @strWhere  --print @strSql EXECUTE sp_executesql @strSql,N'@Total INT OUTPUT',@Total OUTPUTset nocount off;------------------------------------------------------------------------------------------------------------以下调用exec Common_PageList 'TableA','*',' and condition = '第一次' ',1,10,'ddate desc',0;
查看完整描述
  • 2 回答
  • 0 关注
  • 1181 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信