sql server2005 rownumͨÓô洢¹ý³Ì·ÖÒ³
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER PROCEDURE [dbo].[sp_GetRecordfromPage]
@TableName varchar(350), --±íÃû
@Fields varchar(5000) = '*', --×Ö¶ÎÃû(È«²¿×Ö¶ÎΪ*)
@OrderField varchar(5000), --ÅÅÐò×Ö¶Î(±ØÐë!Ö§³Ö¶à×Ö¶Î)
@sqlWhere varchar(5000) = Null,--Ìõ¼þÓï¾ä(²»ÓüÓwhere)
@pageSize int, --ÿҳ¶àÉÙÌõ¼Ç¼
@pageIndex int = 1, --Ö¸¶¨µ±Ç°ÎªµÚ¼¸Ò³
@distinct VARCHAR(50)=NULL, --È¥³ýÖظ´Öµ£¬×¢ÒâÖ»ÄÜÊÇÒ»¸ö×Ö¶Î
@top INT=NULL --²éѯTOP,²»´«ÎªÈ«²¿
AS
BEGIN
Declare @sql nvarchar(4000);
Declare @totalRecord int;
DECLARE @totalPage INT;
--¼ÆËã×ܼǼÊý
IF (@distinct IS NULL OR @distinct='')
BEGIN
IF (@SqlWhere='' OR @sqlWhere IS NULL)
SET @sql = 'select @totalRecord = count(1) from ' + @TableName
ELSE
SET @sql = 'select @totalRecord = count(1) from ' + @TableName + ' where ' + @sqlWhere
END
ELSE
BEGIN
IF (@SqlWhere='' OR @sqlWhere IS NULL)
SET @sql = 'select @totalRecord = count(distinct ' + @distinct + ') from ' + @TableName
ELSE
SET @sql = 'select @totalRecord = count(distinct ' + @distinct + ') from ' + @TableName + ' where ' + @sqlWhere
END
EXEC sp_executesql @sql,N'@totalRecord int OUTPUT',@totalRecord OUTPUT--¼ÆËã×ܼǼÊý
IF(@top>0)
BEGIN
--Ö¸¶¨TOP ¼Ç¼
SET @Fields= 'top ' + CAST(@top AS VARCHAR(20)) + ' ' + @Fields;
--Èç¹û×ܼǼÊý³¬¹ýTOPÊý,Éè×ܼÇÂ
Ïà¹ØÎĵµ£º
##################################################
# ÉùÃ÷£º
# ±¾ÎÄת×ÔCSDN£¬Óû§ID£ºhtl258
# ÔÌûµØÖ·£ºhttp://blog.csdn.net/htl258/archive/2010/04/28/5537416.aspx
####### ......
ÏÂÔصØÖ·£ºhttp://download.csdn.net/source/2384982
----------------------------------------------------------------------------
Èí¼þÃû³Æ£ºÍ¨ÓÃSql±¸·Ý»Ö¸´¹¤¾ß
Ö´ÐгÌÐò£ºiNethink_SqlTool.exe
³ÌÐò°æ±¾£ºV1.0.0.1
----------------------------------------------------------------------------
Md5Öµ:E511 ......
Áª½ÓÌõ¼þ¿ÉÔÚ from »ò WHERE ×Ó¾äÖÐÖ¸¶¨£¬½¨ÒéÔÚ from ×Ó¾äÖÐÖ¸¶¨Áª½ÓÌõ¼þ¡£WHERE ºÍ HAVING ×Ó¾äÒ²¿ÉÒÔ°üº¬ËÑË÷Ìõ¼þ£¬ÒÔ½øÒ»²½É¸Ñ¡Áª½ÓÌõ¼þËùÑ¡µÄÐС£
Áª½Ó¿É·ÖΪÒÔϼ¸Àࣺ
1. ......
ÏÂÔصØÖ·£ºhttp://submain.download.csdn.net/
Ò²¿ÉÒÔÖ±½Ó¸´ÖÆÏÂÃæµÄÄÚÈÝ£¬²¢±£´æÎļþΪ“sql.stx”¡£
#TITLE=SQL
; SQL syntax file written by BUGSoft(BUGSoft@126.com).
#DELIMITER=,(){}[]-+*%/="'~!&|<>?:;.
#QUOTATION1='
#QUOTATION2="
#LINECOMMENT=--
#COMMENTON=/*
#COMMENTOFF=*/ ......