CREATEPROCEDURE GetSearchEnterprise ( @strWherevarchar(3000), @PageSizeint, @PageIndexint ) AS declare@strSQLvarchar(8000) if@PageIndex=1 begin set@strSQL='select top '+str(@PageSize)+' * from t_company where '+@strWhere+'order by companyid desc' end else begin set@strSQL='select top '+str(@PageSize)+' * from t_company where companyid<(select min(tmp_t_company.companyid) from (select top '+str((@PageIndex-1)*@PageSize)+' companyid from t_company where '+@strWhere+' order by companyid desc) as tmp_t_company ) and '+@strWhere+' order by companyid desc' end exec(@strSQL) --print(@strSQL) GO