Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

SQL ServerÖÐDATAADDºÍDATADIFFµÄÓ÷¨

ͨ³££¬ÄãÐèÒª»ñµÃµ±Ç°ÈÕÆںͼÆËãһЩÆäËûµÄÈÕÆÚ£¬ÀýÈ磬ÄãµÄ³ÌÐò¿ÉÄÜÐèÒªÅжÏÒ»¸öÔµĵÚÒ»Ìì»òÕß×îºóÒ»Ìì¡£´ó²¿·ÖÈË´ó¸Å¶¼ÖªµÀÔõÑù°ÑÈÕÆÚ½øÐзָÄê¡¢Ô¡¢Èյȣ©£¬È»ºó½ö½öÓ÷ָî³öÀ´µÄÄê¡¢Ô¡¢ÈյȷÅÔÚ¼¸¸öº¯ÊýÖмÆËã³ö×Ô¼ºËùÐèÒªµÄÈÕÆÚ£¡ÔÚÕâƪÎÄÕÂÀÎÒ½«½ÌÄãÈçºÎʹÓÃDATEADDºÍDATEDIFFº¯ÊýÀ´¼ÆËã³öÔÚÄãµÄ³ÌÐòÖпÉÄÜÄãÒªÓõ½µÄһЩ²»Í¬ÈÕÆÚ¡£
¡¡¡¡ÔÚʹÓñ¾ÎÄÖеÄÀý×Ó֮ǰ£¬Äã±ØÐë×¢ÒâÒÔϵÄÎÊÌâ¡£´ó²¿·Ö¿ÉÄܲ»ÊÇËùÓÐÀý×ÓÔÚ²»Í¬µÄ»úÆ÷ÉÏÖ´ÐеĽá¹û¿ÉÄܲ»Ò»Ñù£¬ÕâÍêÈ«ÓÉÄÄÒ»ÌìÊÇÒ»¸öÐÇÆڵĵÚÒ»ÌìÕâ¸öÉèÖþö¶¨¡£µÚÒ»Ì죨DATEFIRST£©É趨¾ö¶¨ÁËÄãµÄϵͳʹÓÃÄÄÒ»Ìì×÷ΪһÖܵĵÚÒ»Ìì¡£ËùÓÐÒÔϵÄÀý×Ó¶¼ÊÇÒÔÐÇÆÚÌì×÷ΪһÖܵĵÚÒ»ÌìÀ´½¨Á¢£¬Ò²¾ÍÊǵÚÒ»ÌìÉèÖÃΪ7¡£¼ÙÈçÄãµÄµÚÒ»ÌìÉèÖò»Ò»Ñù£¬Äã¿ÉÄÜÐèÒªµ÷ÕûÕâЩÀý×Ó£¬Ê¹ËüºÍ²»Í¬µÄµÚÒ»ÌìÉèÖÃÏà·ûºÏ¡£Äã¿ÉÒÔͨ¹ý@@DATEFIRSTº¯ÊýÀ´¼ì²éµÚÒ»ÌìÉèÖá£
¡¡¡¡ÎªÁËÀí½âÕâЩÀý×Ó£¬ÎÒÃÇÏȸ´Ï°Ò»ÏÂDATEDIFFºÍDATEADDº¯Êý¡£DATEDIFFº¯Êý¼ÆËãÁ½¸öÈÕÆÚÖ®¼äµÄСʱ¡¢Ìì¡¢ÖÜ¡¢Ô¡¢ÄêµÈʱ¼ä¼ä¸ô×ÜÊý¡£DATEADDº¯Êý¼ÆËãÒ»¸öÈÕÆÚͨ¹ý¸øʱ¼ä¼ä¸ô¼Ó¼õÀ´»ñµÃÒ»¸öеÄÈÕÆÚ¡£ÒªÁ˽â¸ü¶àµÄDATEDIFFºÍDATEADDº¯ÊýÒÔ¼°Ê±¼ä¼ä¸ô¿ÉÒÔÔĶÁ΢ÈíÁª»ú°ïÖú¡£
¡¡¡¡Ê¹ÓÃDATEDIFFºÍDATEADDº¯ÊýÀ´¼ÆËãÈÕÆÚ£¬ºÍ±¾À´´Óµ±Ç°ÈÕÆÚת»»µ½ÄãÐèÒªµÄÈÕÆڵĿ¼ÂÇ·½·¨Óе㲻ͬ¡£Äã±ØÐë´Óʱ¼ä¼ä¸ôÕâ¸ö·½ÃæÀ´¿¼ÂÇ¡£±ÈÈ磬´Óµ±Ç°ÈÕÆÚµ½ÄãÒªµÃµ½µÄÈÕÆÚÖ®¼äÓжàÉÙʱ¼ä¼ä¸ô£¬»òÕߣ¬´Ó½ñÌ쵽ijһÌ죨±ÈÈç1900-1-1£©Ö®¼äÓжàÉÙʱ¼ä¼ä¸ô£¬µÈµÈ¡£Àí½âÔõÑù×ÅÑÛÓÚʱ¼ä¼ä¸ôÓÐÖúÓÚÄãÇáËɵÄÀí½â²»Í¬µÄÈÕÆÚ¼ÆËãÀý×Ó¡£
¡¡¡¡Ò»¸öÔµĵÚÒ»Ìì 
¡¡¡¡µÚÒ»¸öÀý×Ó£¬ÈçºÎ´Óµ±Ç°ÈÕÆÚÈ¡Õâ¸öÔµĵÚÒ»Ìì¡£Çë×¢Ò⣺Õâ¸öÀý×ÓÒÔ¼°ÕâƪÎÄÕÂÖеÄÆäËûÀý×Ó¶¼½«Ö»Ê¹ÓÃDATEDIFFºÍDATEADDº¯ÊýÀ´¼ÆËãÎÒÃÇÏëÒªµÄÈÕÆÚ¡£Ã¿Ò»¸öÀý×Ó¶¼½«Í¨¹ý¼ÆË㵱ǰµÄʱ¼ä¼ä¸ô£¬È»ºó½øÐмӼõÀ´µÃµ½ÏëÒª¼ÆËãµÄÈÕÆÚ¡£
¡¡¡¡ÕâÊǼÆËãÒ»¸öÔµÚÒ»ÌìµÄSQL  ½Å±¾£º 
¡¡¡¡select  DATEADD(mm,  DATEDIFF(mm,0,getdate()),  0)  
¡¡¡¡ÎÒÃÇ°ÑÕâ¸öÓï¾ä·Ö¿ªÀ´¿´¿´ËüÊÇÈçºÎ¹¤×÷µÄ¡£×îºËÐĵĺ¯ÊýÊÇgetdate()£¬´ó²¿·ÖÈ˶¼ÖªµÀÕâ¸öÊÇ·µ»Øµ±Ç°µÄÈÕÆÚºÍʱ¼äµÄº¯Êý¡£ÏÂÒ»¸öÖ´Ðеĺ¯ÊýDATEDIFF(mm,0,getdate())ÊǼÆË㵱ǰÈÕÆں͓1900-01-01¡¡00:00:00.000”Õâ¸öÈÕÆÚÖ®¼äµÄÔÂÊý¡£¼Çס£ºÊ±ÆÚºÍʱ¼ä±äÁ¿ºÍºÁÃëÒ»ÑùÊÇ´Ó“1900-01-01  00:00:00.000”¿ªÊ¼¼ÆËãµÄ¡£


Ïà¹ØÎĵµ£º

Áù¸ö·ÀÖ¹SQL×¢Èëʽ¹¥»÷µÄ½¨Òé

Áù¸ö·ÀÖ¹SQL×¢Èëʽ¹¥»÷µÄ½¨Òé
http://blog.csdn.net/jefflam/archive/2009/06/01/4233359.aspx
SQL×¢Èë¹¥»÷µÄΣº¦ÐԺܴó¡£ÔÚ½²½âÆä·ÀÖ¹°ì·¨Ö®Ç°£¬Êý¾Ý¿â¹ÜÀíÔ±ÓбØÒªÏÈÁ˽âÒ»ÏÂÆä¹¥»÷µÄÔ­Àí¡£ÕâÓÐÀûÓÚ¹ÜÀíÔ±²ÉÈ¡ÓÐÕë¶ÔÐԵķÀÖδëÊ©¡£
¡¡¡¡Ò»¡¢ SQL×¢Èë¹¥»÷µÄ¼òµ¥Ê¾Àý¡£
¡¡¡¡statement := "SELECT * from Users WHERE Va ......

Áù¸ö·ÀÖ¹SQL×¢Èëʽ¹¥»÷µÄ½¨Òé

SQL×¢Èë¹¥»÷µÄΣº¦ÐԺܴó¡£ÔÚ½²½âÆä·ÀÖ¹°ì·¨Ö®Ç°£¬Êý¾Ý¿â¹ÜÀíÔ±ÓбØÒªÏÈÁ˽âÒ»ÏÂÆä¹¥»÷µÄÔ­Àí¡£ÕâÓÐÀûÓÚ¹ÜÀíÔ±²ÉÈ¡ÓÐÕë¶ÔÐԵķÀÖδëÊ©¡£
¡¡¡¡Ò»¡¢ SQL×¢Èë¹¥»÷µÄ¼òµ¥Ê¾Àý¡£
¡¡¡¡statement := "SELECT * from Users WHERE Value= " + a_variable + "
¡¡¡¡ÉÏÃæÕâÌõÓï¾äÊǺÜÆÕͨµÄÒ»ÌõSQLÓï¾ä£¬ËûÖ÷ҪʵÏֵŦÄܾÍÊÇÈÃÓû§Ê ......

ǶÈëʽSQLʵÑé


ʵÑéÄÚÈÝ£º
ÕÆÎÕSQL Server 2000µÄÔ¤±àÒë³ÌÐòNSQLPREP.EXEµÄʹÓã¨ÒԿα¾ÀýÌâ1½øÐе÷ÊÔ£©£»
ʵÑé²½Ö裺
Ò»¡¢Êý¾Ý¿â»·¾³ÅäÖÃ
1¡¢´´½¨xueshengÊý¾Ý¿â£¬½¨Á¢student±íµÈ£»
2¡¢¹Ø±Õsql server 2000·þÎñ¹ÜÀíÆ÷£»
3¡¢½«devtoolsÎļþ¼Ð¿½±´µ½£ºC:\Program Files\Microsoft SQL Server
4¡¢½«BinnÎļþ¼Ð¿½±´µ½£ºC:\Program ......

SQL´æ´¢¹ý³ÌÈëÃÅ ÄÏÈý·½

Ò»¡¢SQL´æ´¢¹ý³ÌµÄ¸ÅÄÓŵ㼰Óï·¨ 
¡¡¡¡ÕûÀíÔÚѧϰ³ÌÐò¹ý³Ì֮ǰ£¬ÏÈÁ˽âÏÂʲôÊÇ´æ´¢¹ý³Ì?ΪʲôҪÓô洢¹ý³Ì£¬ËûÓÐÄÇЩÓŵã
¡¡¡¡¶¨Ò壺½«³£ÓõĻòºÜ¸´ÔӵŤ×÷£¬Ô¤ÏÈÓÃSQLÓï¾äдºÃ²¢ÓÃÒ»¸öÖ¸¶¨µÄÃû³Æ´æ´¢ÆðÀ´, ÄÇôÒÔºóÒª½ÐÊý¾Ý¿âÌṩÓëÒѶ¨ÒåºÃµÄ´æ´¢¹ý³ÌµÄ¹¦ÄÜÏàͬµÄ·þÎñʱ,Ö»Ðèµ÷ÓÃexecute,¼´¿É×Ô¶¯Íê³ÉÃüÁî ......

sql server µ¼Èëµ¼³öÊý¾Ýµ½execl

1 Export data to existing EXCEL file
from SQL Server table
insert into OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'Excel 8.0;Database=D:\testing.xls;',
'SELECT * from [SheetName$]') select * from SQLServerTable
2 Export data from Excel to new SQL Server table
select *
into SQLServerTab ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ