Ó²ÅÌÊý¾Ý»Ö¸´µ¼º½
RAIDÊý¾Ý»Ö¸´µ¼º½
 | ÍøÕ¾Ê×Ò³ | Êý¾Ý»Ö¸´×ÊÁÏ | Êý¾Ý»Ö¸´Èí¼þ | ×ÉѯÁôÑÔ | Êý¾Ý»Ö¸´²©¿Í | Êý¾Ý»Ö¸´ÂÛ̳ | 
Êý¾Ý»Ö¸´Èí¼þÏÂÔØ
Êý¾Ý»Ö¸´·þÎñ Êý¾Ý»Ö¸´ Êý¾Ý»Ö¸´±¨¼Û Êý¾Ý»Ö¸´Åàѵ Êý¾Ý»Ö¸´ÊµÑéÊÒ Êý¾Ý»Ö¸´Ñо¿³É¹û Êý¾Ý»Ö¸´·þÎñÁªÏµ·½Ê½
ÄúÏÖÔÚµÄλÖ㺠±±ÑÇÊý¾Ý»Ö¸´¼¼ÊõÕ¾ >> Êý¾Ý»Ö¸´×ÊÁÏ >> Ïà¹Ø±à³Ì×ÊÁÏ >> ÎÄÕÂÕýÎÄ
SQLServer·ÖÒ³²éѯͨÓô洢¹ý³Ì            ¡¾×ÖÌ壺С ´ó¡¿
SQLServer·ÖÒ³²éѯͨÓô洢¹ý³Ì
×÷ÕߣºØýÃû    ÎÄÕÂÀ´Ô´£º»¥ÁªÍø    µã»÷Êý£º    ¸üÐÂʱ¼ä£º2007-03-02

×Ô¿ªÊ¼×öÏîÄ¿ÒÔÀ´£¬Ò»Ö±ÔÚÓá£Õâ¶Î´æ´¢¹ý³ÌµÄµÄÔ­´´Õߣ¨SORRY£¬Íü¼ÇÃû×ÖÁË£©£¬Ð´µÃÕâ¶ÎSQL´úÂëºÜ²»´í£¬ÎÒÔÚÕâ¸ö»ù´¡ÉÏ£¬°´ÕÕÎÒµÄÏ°¹ßÒÔ¼°Ë¼Î¬·½Ê½£¬µ÷ÕûÁË´úÂ룬ֻ×ö·ÖÒ³²éѯÓá£

/**//*----------------------------------------------
 *procedure name : prcPageResult
 *  author : FuChun
 *  create date : 2006-10-04
 */
CREATE PROCEDURE prcPageResult
-- »ñµÃijһҳµÄÊý¾Ý --
@currPage int = 1,                                    --µ±Ç°Ò³Ò³Âë (¼´Top currPage)
@showColumn varchar(2000) = '*',           --ÐèÒªµÃµ½µÄ×ֶΠ(¼´ column1,column2,......)
@tabName varchar(2000),                           --ÐèÒª²é¿´µÄ±íÃû (¼´ from table_name)
@strCondition varchar(2000) = '',              --²éѯÌõ¼þ (¼´ where condition......) ²»ÓüÓwhere¹Ø¼ü×Ö
@ascColumn varchar(100) = '',                 --ÅÅÐòµÄ×Ö¶ÎÃû (¼´ order by column asc/desc)
@bitOrderType bit = 0,                            --ÅÅÐòµÄÀàÐÍ (0ΪÉýÐò,1Ϊ½µÐò)
@pkColumn varchar(50) = '',                   --Ö÷¼üÃû³Æ
@pageSize int = 20                                --·ÖÒ³´óС

AS
BEGIN -- ´æ´¢¹ý³Ì¿ªÊ¼
-- ¸Ã´æ´¢¹ý³ÌÐèÒªÓõ½µÄ¼¸¸ö±äÁ¿ http://www.knowsky.com/ --
DECLARE @strTemp varchar(1000)
DECLARE @strSql varchar(4000)                   --¸Ã´æ´¢¹ý³Ì×îºóÖ´ÐеÄÓï¾ä
DECLARE @strOrderType varchar(1000)      --ÅÅÐòÀàÐÍÓï¾ä (order by column asc»òÕßorder by column desc)

BEGIN
IF @bitOrderType = 1   -- bitOrderType=1¼´Ö´ÐнµÐò
BEGIN
    SET @strOrderType = ' ORDER BY '+@ascColumn+' DESC'
    SET @strTemp = '<(SELECT min'
END
ELSE
BEGIN
    SET @strOrderType = ' ORDER BY '+@ascColumn+' ASC'
    SET @strTemp = '>(SELECT max'
END

IF @currPage = 1    -- Èç¹ûÊǵÚÒ»Ò³
BEGIN
    IF @strCondition != ''
        SET @strSql = 'SELECT TOP '+STR(@pageSize)+' '+@showColumn+' FROM '+@tabName+
            ' WHERE '+@strCondition+@strOrderType
    ELSE
        SET @strSql = 'SELECT TOP '+STR(@pageSize)+' '+@showColumn+' FROM '+@tabName+@strOrderType
END

ELSE    -- ÆäËûÒ³
BEGIN
    IF @strCondition !=''
        SET @strSql = 'SELECT TOP '+STR(@pageSize)+' '+@showColumn+' FROM '+@tabName+
        ' WHERE '+@strCondition+' AND '+@pkColumn+@strTemp+'('+@pkColumn+')'+' FROM (SELECT TOP '+STR((@currPage-1)*@pageSize)+
        ' '+@pkColumn+' FROM '+@tabName+@strOrderType+') AS TabTemp)'+@strOrderType
    ELSE
        SET @strSql = 'SELECT TOP '+STR(@pageSize)+' '+@showColumn+' FROM '+@tabName+
        ' WHERE '+@pkColumn+@strTemp+'('+@pkColumn+')'+' FROM (SELECT TOP '+STR((@currPage-1)*@pageSize)+' '+@pkColumn+
        ' FROM '+@tabName+@strOrderType+') AS TabTemp)'+@strOrderType
END

END
EXEC (@strSql)
END  -- ´æ´¢¹ý³Ì½áÊø
------------------------------------------------
GO
 µ÷Ó÷½·¨£º

prcPageResult 1,'*','TableName','','CreateDate',1,'PkID',25

 ÉÏÃæ±íʾ£¬²éѯ±íTableNameµÄËùÓÐ×ֶΣ¬Ç°25Ìõ¼Ç¼£¬ÒòΪÊǵÚÒ»Ò³£¬ÅÅÐò×Ö¶ÎΪCreateDate£¬½µÐòÅÅÁУ¬Ö÷¼üÊÇPkID¡£Õâ¸ö´æ´¢¹ý³ÌµÄ¹¦ÄܱȽÏÇ¿´ó£¬ÓÃÔÚÏîÄ¿Öзdz£µÄÊÊÓᣲ»ÐÅÄú¿ÉÒÔÊÔÊÔ¿´£¬ÓÈÆäÊÇÔÚ°ÙÍò¼¶Êý¾ÝÉÏ£¬ËûµÄÓÅÊƾÍÏÔ¶ÎÞÒÉÁË£¬µ±È»£¬Õâ¶Î´úÂëÊÇ¿ÉÒÔת»»³ÉMySqlÖеĴ洢¹ý³ÌµÄ£¬²»¹ý£¬ÔÚÕâÀï¾Í²»¸ø´ó¼ÒÁË£¬ÄãÃÇ¿ÉÒÔ×Ô¼ºÊÔ×Åת»»¿´¿´¡£

ÏÂÃæµÄ´æ´¢¹ý³Ì²éѯ±íµÄ¼Ç¼Êý£º

/**//*----------------------------------------------
 *procedure name : prcRowsCount
 *  author : FuChun
 *  create date : 2006-09-22
 */
CREATE PROC prcRowsCount
@tabName varchar(200),            --ÐèÒª²éѯµÄ±íÃû
@colName varchar(200)='*',        --ÐèÒª²éѯµÄÁÐÃû
@condition varchar(200)=''       --²éѯÌõ¼þ
AS
BEGIN
    DECLARE @strSql varchar(255)
    IF @condition = ''
        SET @strSql='select count('+@colName+') from '+@tabName
    ELSE
        SET @strSql='select count('+@colName+') from '+@tabName+' where '+@condition
    EXEC (@strSql)
END
------------------------------------------------
GO
»¹ÓÐɾ³ý¼Ç¼µÄͨÓô洢¹ý³ÌºÍ²éѯµ¥Ìõ¼Ç¼µÄͨÓô洢¹ý³ÌÔÚÕâÀï¾Í²»·îËÍÁË£¬¸ÐлÌṩԭͨÓ÷ÖÒ³²éѯ´æ´¢¹ý³ÌµÄ¸çÃÇ£¬Ð»Ð»¡£
http://blog.csdn.net/fcrpg2005/archive/2007/02/22/1512707.aspx

 

ÎÄÕ¼È룺Ʈ    ÔðÈα༭£ºÆ® 
  • ÉÏһƪÎÄÕ£º

  • ÏÂһƪÎÄÕ£º
  • ¡¾·¢±íÆÀÂÛ¡¿¡¾¼ÓÈëÊղء¿¡¾¸æËߺÃÓÑ¡¿¡¾´òÓ¡´ËÎÄ¡¿¡¾¹Ø±Õ´°¿Ú¡¿
    ÍøÓÑÆÀÂÛ£º£¨Ö»ÏÔʾ×îÐÂ10Ìõ¡£ÆÀÂÛÄÚÈÝÖ»´ú±íÍøÓѹ۵㣬Óë±¾Õ¾Á¢³¡Î޹أ¡£©
    ¹ØÓÚÎÒÃÇ | RAIDÊý¾Ý»Ö¸´ | ÓÑÇéÁ´½Ó | RSSÉú³É | XMLÉú³É | ÎÄÕÂHTMLµØͼ | ÏÂÔØHTMLµØͼ

    È«¹úͳһ¿Í·þµç»°:4006-505-808
    ×ܲ¿µç»°£º010-82488636 ÓÊÏä:ycf@frombyte.com
    ¹«Ë¾µØÖ·£º±±¾©Êк£µíÇøÓÀ·á»ùµØ·á»ÛÖз7ºÅвÄÁÏ´´Òµ´óÏÃB×ù205ÊÒ
    ¾©ICP±¸05011939
    ×Ð/