![]() | CYQ.Data componentsCYQ.Data support multi-database application [Txt,Xml,Access, MSSQL, Oracle,SQLite,MySql], help easily and quickly to develop your project |
CYQ.Data 数据框架 SQL2005 分页存储过程
Principles |
|
|
| #TopicOwner |
下面是CYQ.Data 数据框架在SQL2005的分页存储过程的代码: Create procedure [SelectBase] @PageIndex int, @PageSize int, @TableName nvarchar(4000), @Where nvarchar(max)='' as Declare @rowcount int Declare @intStart int Declare @intEnd int Declare @SQl nvarchar(max), @WhereR nvarchar(max), @OrderBy nvarchar(max) set @rowcount=0 set nocount on if @Where<>'' begin set @Where=' and '+@Where end if CHARINDEX('order by', @Where)>0 begin set @WhereR=substring(@Where, 1, CHARINDEX('order by',@Where)-1) --取得条件 set @OrderBy=substring(@Where, CHARINDEX('order by',@Where), Len(@Where)) --取得排序方式(order by 字段 方式) end else begin set @WhereR=@Where set @OrderBy=' order by id asc' end set @SQl='SELECT @rowcount=count(*) from '+cast(@TableName as varchar(4000))+' where 1=1 '+@WhereR exec sp_executeSql @SQl,N'@rowcount int output',@rowcount output if @PageIndex=0 and @PageSize=0 --不进行分页,查询所有数据列表 begin set @SQl='SELECT * from '+cast(@TableName as varchar(4000))+' where 1=1 '+@Where end else --进行分页查询数据列表 begin set @intStart=(@PageIndex-1)*@PageSize+1; set @intEnd=@intStart+@PageSize-1 set @SQl='select * from(select *,ROW_NUMBER() OVER('+cast(@OrderBy as nvarchar(400))+') as row from ' set @SQl=@SQL+@TableName+' where 1=1 '+@WhereR+') as a where row between '+cast(@intStart as varchar)+' and '+cast(@intEnd as varchar) end exec sp_executeSql @SQl return @rowcount set nocount off ![]() |
Post Comment
Bulletin
Article Search
Categories
- Platform for dynamic (20)
- Feedback (9)
- Guide (33)
- Principles (19)
- Project-Case (8)
- Business & Buy (2)
- Technology exchange (45)
New Article
- CYQ.Data Components Getting Started Guide [Part 5]-[MProc Execute Stored Procedures or SQL]
- CYQ.Data Components Getting Started Guide [Part 4]-[MAction Insert Delete Update]
- CYQ.Data Components Getting Started Guide [Part 3]-[MAction Get And Set Value]
- CYQ.Data Components Getting Started Guide [Part 2]-[MAction Data Query- Fill And Select]
- CYQ.Data Components Getting Started Guide [Part 1]
New Comment
- When some one searches for his necessary thing, therefore he/she wishes to be available that in detail, so that thing is maintained over here.
- This is my first time pay a quick visit at here and i am in fact happy to read everthing at alone place.
- I truly appreciate this blog article.Really thank you! Cool.
- please pay a visit to the web sites we follow, like this one particular, as it represents our picks in the web
- Really enjoyed this post.Really thank you!
- Really enjoyed this article.Really looking forward to read more. Great.
- poker bonuses What are the norms of copyright of web content? How as it different from Patent?
- Wow! Thank you! I permanently needed to write on my blog something like that. Can I implement a fragment of your post to my site?
- This website was how do I say it? Relevant!! Finally I ave found something that helped me. Cheers!
- I was reading through some of your content on this internet site and I believe this web site is very informative ! Continue posting.