最优化查询代码
create proc DoctorDetailed@CreaterTime time,--开始时间@EndTime time,--结束时间@page int,--页码@rows int,--页数@DoctorName Nvarchar(20),--医生名字 ASbegindeclare @sql1 nvarchar(400)declare @sql2 nvarchar(400)declare @page1 intdeclare @rows1 int --此处为分页计算 set @page1=(@page-1)*@rows+1 set @rows1= @page*@rowsset @sql1 =' SELECT * FROM (select ROW_NUMBER() OVER(ORDER BY '排序字段' desc ) AS rownum,* from( select * from as '需要查询的内容' ) as A where 1=1' set @sql2=' ) AS Dwhere where 1=1 '--多条件查询,判断是否字符串传进来为空,不为空则加上条件查询 IF @DoctorName!='' BEGIN SET @sql1=@sql1+ ' AND Dwhere.条件查询的列名字(例子:Dwhere.DoctorName)='''+@DoctorName+''' ' END --分页条件查询 此处传进来的 页数 需要 转换 SET @sql2=@sql2+ 'AND rownum between '+cast(@page1 as varchar(10))+' and '+cast(@rows1 as varchar(10))+'' end