SQL Server ÄêÔÂÈÕ¼ÆËã
SQL Server 2000/2005 ÄêÔÂÈÕ¼ÆËã·½·¨
ͨ³££¬ÄãÐèÒª»ñµÃµ±Ç°ÈÕÆںͼÆËãһЩÆäËûµÄÈÕÆÚ£¬ÀýÈ磬ÄãµÄ³ÌÐò¿ÉÄÜÐèÒªÅжÏÒ»¸öÔµĵÚÒ»Ìì»òÕß×îºóÒ»Ìì¡£ÄãÃÇ´ó²¿
·ÖÈË´ó¸Å¶¼ÖªµÀÔõÑù°ÑÈÕÆÚ½øÐзָÄê¡¢Ô¡¢Èյȣ©£¬È»ºó½ö½öÓ÷ָî³öÀ´µÄÄê¡¢Ô¡¢ÈյȷÅÔÚ¼¸¸öº¯ÊýÖмÆËã³ö×Ô¼ºËùÐèÒªµÄÈÕÆÚ£¡ÔÚÕâƪÎÄÕÂÀÎÒ½«¸æËßÄã
ÈçºÎʹÓÃDATEADDºÍDATEDIFFº¯ÊýÀ´¼ÆËã³öÔÚÄãµÄ³ÌÐòÖпÉÄÜÄãÒªÓõ½µÄһЩ²»Í¬ÈÕÆÚ¡£
ÔÚʹÓñ¾ÎÄÖеÄÀý×Ó֮ǰ£¬Äã±ØÐë×¢ÒâÒÔϵÄÎÊÌâ¡£´ó²¿·Ö¿ÉÄܲ»ÊÇËùÓÐÀý×ÓÔÚ²»Í¬µÄ»úÆ÷ÉÏÖ´ÐеĽá¹û¿ÉÄܲ»Ò»Ñù£¬ÕâÍêÈ«ÓÉÄÄÒ»ÌìÊÇÒ»¸öÐÇÆڵĵÚÒ»ÌìÕâ¸öÉèÖÃ
¾ö¶¨¡£µÚÒ»Ì죨DATEFIRST£©É趨¾ö¶¨ÁËÄãµÄϵͳʹÓÃÄÄÒ»Ìì×÷ΪһÖܵĵÚÒ»Ìì¡£ËùÓÐÒÔϵÄÀý×Ó¶¼ÊÇÒÔÐÇÆÚÌì×÷ΪһÖܵĵÚÒ»ÌìÀ´½¨Á¢£¬Ò²¾ÍÊǵÚÒ»ÌìÉè
ÖÃΪ7¡£¼ÙÈçÄãµÄµÚÒ»ÌìÉèÖò»Ò»Ñù£¬Äã¿ÉÄÜÐèÒªµ÷ÕûÕâЩÀý×Ó£¬Ê¹ËüºÍ²»Í¬µÄµÚÒ»ÌìÉèÖÃÏà·ûºÏ¡£Äã¿ÉÒÔͨ¹ý@@DATEFIRSTº¯ÊýÀ´¼ì²éµÚÒ»ÌìÉèÖá£
ΪÁËÀí½âÕâЩÀý×Ó£¬ÎÒÃÇÏȸ´Ï°Ò»ÏÂDATEDIFFºÍDATEADDº¯Êý¡£DATEDIFFº¯Êý¼ÆËãÁ½¸öÈÕÆÚÖ®¼äµÄСʱ¡¢Ìì¡¢ÖÜ¡¢Ô¡¢ÄêµÈʱ¼ä¼ä¸ô×ÜÊý¡£
DATEADDº¯Êý¼ÆËãÒ»¸öÈÕÆÚͨ¹ý¸øʱ¼ä¼ä¸ô¼Ó¼õÀ´»ñµÃÒ»¸öеÄÈÕÆÚ¡£ÒªÁ˽â¸ü¶àµÄDATEDIFFºÍDATEADDº¯ÊýÒÔ¼°Ê±¼ä¼ä¸ô¿ÉÒÔÔĶÁ΢ÈíÁª»ú
°ïÖú¡£
ʹÓÃDATEDIFFºÍDATEADDº¯ÊýÀ´¼ÆËãÈÕÆÚ£¬ºÍ±¾À´´Óµ±Ç°ÈÕÆÚת»»µ½ÄãÐèÒªµÄÈÕÆڵĿ¼ÂÇ·½·¨Óе㲻ͬ¡£Äã±ØÐë´Óʱ¼ä¼ä¸ôÕâ¸ö·½ÃæÀ´¿¼ÂÇ¡£±ÈÈ磬
´Óµ±Ç°ÈÕÆÚµ½ÄãÒªµÃµ½µÄÈÕÆÚÖ®¼äÓжàÉÙʱ¼ä¼ä¸ô£¬»òÕߣ¬´Ó½ñÌ쵽ijһÌ죨±ÈÈç1900-1-1£©Ö®¼äÓжàÉÙʱ¼ä¼ä¸ô£¬µÈµÈ¡£Àí½âÔõÑù×ÅÑÛÓÚʱ¼ä¼ä¸ôÓÐÖúÓÚ
ÄãÇáËɵÄÀí½âÎҵIJ»Í¬µÄÈÕÆÚ¼ÆËãÀý×Ó¡£
Ò»¸öÔµĵÚÒ»Ìì
µÚÒ»¸öÀý×Ó£¬ÎÒ½«¸æËßÄãÈçºÎ´Óµ±Ç°ÈÕÆÚÈ¥Õâ¸öÔµÄ×îºóÒ»Ìì¡£Çë×¢Ò⣺Õâ¸öÀý×ÓÒÔ¼°ÕâƪÎÄÕÂÖеÄÆäËûÀý×Ó¶¼½«Ö»Ê¹ÓÃDATEDIFFºÍDATEADDº¯ÊýÀ´¼ÆËãÎÒÃÇÏëÒªµÄÈÕÆÚ¡£Ã¿Ò»¸öÀý×Ó¶¼½«Í¨¹ý¼ÆË㵫ǰµÄʱ¼ä¼ä¸ô£¬È»ºó½øÐмӼõÀ´µÃµ½ÏëÒª¼ÆËãµÄÈÕÆÚ¡£
ÕâÊǼÆËãÒ»¸öÔµÚÒ»ÌìµÄSQL ½Å±¾£º
SELECT DATEADD(mm, DATEDIFF(mm,0,getdate()), 0)
ÎÒÃÇ°ÑÕâ¸öÓï¾ä·Ö¿ªÀ´¿´¿´ËüÊÇÈç
Ïà¹ØÎĵµ£º
create PROCEDURE pagelist
@tablename nvarchar(50),
@fieldname nvarchar(50)='*',
@pagesize int output,--ÿҳÏÔʾ¼Ç¼ÌõÊý
@currentpage int output,--µÚ¼¸Ò³
@orderid nvarchar(50),--Ö÷¼üÅÅÐò
@sort int,--ÅÅÐò·½Ê½£¬1±íʾÉýÐò£¬0±íʾ½µÐòÅÅÁÐ
......
ϵͳ»·¾³£ºWindows 7
Èí¼þ»·¾³£ºVisual C++ 2008 SP1 +SQL Server 2005
±¾´ÎÄ¿µÄ£º±àдһ¸öº½¿Õ¹ÜÀíϵͳ
ÕâÊÇÊý¾Ý¿â¿Î³ÌÉè¼ÆµÄ³É¹û£¬ËäÈ»³É¼¨²»¼Ñ£¬µ«ÊÇ×÷ΪÎÒÓÃVC++ ÒÔÀ´±àдµÄ×î´ó³ÌÐò»¹ÊÇ´«µ½ÍøÉÏ£¬ÒÔ¹©²Î¿¼¡£ÓÃVC++ ×öÊý¾Ý¿âÉè¼Æ²¢²»ÈÝÒ×£¬µ«Ò²²»ÊDz»¿ÉÄÜ¡£ÒÔÏÂÊÇÎҵijÌÐò½çÃ棬ºóÃæ ......
1. ¶¨ÒåÓα궨Òå
ÓαêÓï¾äµÄºËÐÄÊǶ¨ÒåÁËÒ»¸öÓαê±êʶÃû£¬²¢°ÑÓαê±êʶÃûºÍÒ»¸ö²éѯÓï¾ä¹ØÁªÆðÀ´¡£DECLAREÓï¾äÓÃÓÚÉùÃ÷Óα꣬Ëüͨ¹ýSELECT²éѯ¶¨ÒåÓαê´æ´¢µÄÊý¾Ý¼¯ºÏ¡£Óï¾ä¸ñʽΪ£º
DECLARE ÓαêÃû³Æ [INSENSITIVE] [SCROLL]
CURSOR FOR selectÓï¾ä
[FOR{READ ONLY|UPDATE[OF ÁÐÃû×Ö±í]}]
²ÎÊý˵Ã÷£º
INSENSITIVEÑ¡Ï ......
½ñÌìÖÕÓÚÖªµÀSQL 2005 ÔõôÓÃÁË£¬¸Ð¾õÒÔÇ°Ì«ÀÁÁË£¬Ã÷Ã÷ÏëÖªµÀµÄ¶«Î÷¿ÉÊÇÒòΪÒѾÓÐsql2000¾ÍÀÁµÃ²é¡£ÖªÊ¶ÕⶫÎ÷ÊÇÈÕ»ýÔÂÀ۵ģ¬ÕæÕýµ½ÓõÄʱºò²ÅÈ¥²¹¾ÍÒѾÍíÁË¡£
ÒÔÇ°°²×°VS2005µÄʱºò¾Í¿´µ½°²×°ÍêÁËÒÔºó»áÓÐÒ»¸öSQL2005£¬¿ÉÊÇ×Ô¼º²»»áÓã¬ÄǸöʱºòÖ» ......
µ±SQLServerµÄϵͳÈÕÖ¾¹ý´ó£¬¾Í»áÒýÆðSQLServer·þÎñÆ÷ÎÞ·¨Æô¶¯µÈһϵÁÐÎÊÌâ¡£½ñÌìÎÒÓöµ½ÁËÕâ¸öÎÊÌ⣬ÔÚÍøÉÏËÑË÷ÁËһϣ¬½â¾ö·½·¨ÊÇɾ³ý¾Í¿ÉÒÔÁË£¬¿ÉÊǵ±Ç°µÄErrorLogÕýÔÚ±»SQLʹÓÃÎÞ·¨É¾³ý°¡£¬ÒªÉ¾³ýÖ»ÄÜÍ£Ö¹SQL·þÎñÆ÷£¬ÄѵÀ¾ÍûÓбðµÃ°ì·¨ÁËÂð£¿
»Ø´ðÊǿ϶¨µÄ£ºÊ¹ÓÃÒÔÏ´洢¹ý³Ì£º ......