分页函数

 1 --创建分页函数
 2 USE stus
 3 GO
 4 CREATE FUNCTION getfyss(@page INT,@count INT,@table VARCHAR(20))
 5 RETURNS nVARCHAR(800)
 6 AS
 7 BEGIN
 8     DECLARE @str nVARCHAR(800) 
 9     SET @str=
10     'SELECT TOP ' +CONVERT(VARCHAR(10),(@count))+' * FROM '+@table+' where id not in'+
11     ' (select top '+CONVERT(VARCHAR(10),((@page-1)*@count))+' id from '+@table+')'
12     RETURN @str
13 END
14 GO
15 --删除函数
16 --DROP FUNCTION dbo.getfyss
17 --调用分页函数
18 DECLARE @str nVARCHAR(800) 
19 SELECT @str=dbo.getfyss(2,3,'stu')
20 EXECUTE  sp_executesql @str
21 
22 怎么把函数转换成存储过程呢?其实学习就是一个举一反三的过程,动动脑筋,你会发觉你的智商越来越高的O(∩_∩)O~

 

posted @ 2013-05-27 14:27  宁静思远  阅读(125)  评论(0编辑  收藏  举报