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

SQLserverʱ¼ä¶Î²éѯ

eg:
select * from Exception_Log where DATEDIFF(day,OPER_DATE,getdate())<30 ;
/*
oper_date Ϊ±íÖвéѯ³öÀ´µÄʱ¼ä
getdate()ΪSQLServerÀïÃæ»ñµÃϵͳʱ¼äµÄº¯Êý
º¬Ò壺µ±Ç°Ê±¼ä-²éѯ³öÀ´µÄʱ¼äСÓÚ30Ìì
DateDiff¾ßÌåÓ÷¨£º
*/
DateDiff º¯Êý
·µ»ØÁ½¸öÈÕÆÚÖ®¼äµÄʱ¼ä¼ä¸ô¡£
DateDiff(interval, date1, date2 [,firstdayofweek[, firstweekofyear]])
DateDiff º¯ÊýµÄÓï·¨ÓÐÒÔϲÎÊý£º
²ÎÊý
interval
±ØÑ¡Ïî¡£String expression ±íʾÓÃÓÚ¼ÆËã date1 ºÍ date2 Ö®¼äµÄʱ¼ä¼ä¸ô¡£ÓйØÊýÖµ£¬Çë²ÎÔÄ“ÉèÖÔ²¿·Ö¡£
date1, date2
±ØÑ¡Ïî¡£ÈÕÆÚ±í´ïʽ¡£ÓÃÓÚ¼ÆËãµÄÁ½¸öÈÕÆÚ¡£
Firstdayofweek
¿ÉÑ¡Ïî¡£Ö¸¶¨ÐÇÆÚÖеÚÒ»ÌìµÄ³£Êý¡£Èç¹ûûÓÐÖ¸¶¨£¬ÔòĬÈÏΪÐÇÆÚÈÕ¡£ÓйØÊýÖµ£¬Çë²ÎÔÄ“ÉèÖÔ²¿·Ö¡£
Firstweekofyear
¿ÉÑ¡Ïî¡£Ö¸¶¨Ò»ÄêÖеÚÒ»Öܵij£Êý¡£Èç¹ûûÓÐÖ¸¶¨£¬ÔòĬÈÏΪ 1 Ô 1 ÈÕËùÔÚµÄÐÇÆÚ¡£ÓйØÊýÖµ£¬Çë²ÎÔÄ“ÉèÖÔ²¿·Ö¡£
ÉèÖÃ
interval ²ÎÊý¿ÉÒÔÓÐÒÔÏÂÖµ£º
ÉèÖà  ÃèÊö
yyyy  Äê
q  ¼¾¶È
m  ÔÂ
y  Ò»ÄêµÄÈÕÊý
d  ÈÕ
w  Ò»ÖܵÄÈÕÊý
ww ÖÜ
h  Ð¡Ê±
n  ·ÖÖÓ
s  Ãë
firstdayofweek ²ÎÊý¿ÉÒÔÓÐÒÔÏÂÖµ£º
³£Êý   Öµ  ÃèÊö
vbUseSystem 0  Ê¹ÓÃÇøÓòÓïÑÔÖ§³Ö (NLS) API ÉèÖá£
vbSunday  1  ÐÇÆÚÈÕ£¨Ä¬ÈÏ£©
vbMonday  2  ÐÇÆÚÒ»
vbTuesday  3  ÐÇÆÚ¶þ
vbWednesday 4  ÐÇÆÚÈý
vbThursday  5  ÐÇÆÚËÄ
vbFriday  6  ÐÇÆÚÎå
vbSaturday  7  ÐÇÆÚÁù
firstweekofyear ²ÎÊý¿ÉÒÔÓÐÒÔÏÂÖµ£º
³£Êý    Öµ  ÃèÊö
vbUseSystem  0  Ê¹ÓÃÇøÓòÓïÑÔÖ§³Ö (NLS) API ÉèÖá£
vbFirstJan1  1  ÓÉ 1 Ô 1 ÈÕËùÔÚµÄÐÇÆÚ¿ªÊ¼£¨Ä¬ÈÏ£©¡£
vbFirstFourDays  2  ÓÉÔÚÐÂÄêÖÐÖÁÉÙÓÐËÄÌìµÄµÚÒ»ÖÜ¿ªÊ¼¡£
vbFirstFullWeek  3  ÓÉÔÚеÄÒ»ÄêÖеÚÒ»¸öÍêÕûµÄÖÜ¿ªÊ¼¡£
˵Ã÷
DateDiff º¯ÊýÓÃÓÚÅжÏÔÚÁ½¸öÈÕÆÚÖ®¼ä´æÔÚµÄÖ¸¶¨Ê±¼ä¼ä¸ôµÄÊýÄ¿¡£ÀýÈç¿ÉÒÔʹÓà DateDiff ¼ÆËãÁ½¸öÈÕÆÚÏà²îµÄÌìÊý£¬»òÕßµ±Ììµ½µ±Äê×îºóÒ»ÌìÖ®¼äµÄÐÇÆÚÊý¡£
Òª¼ÆËã date1 ºÍ date2 Ïà²îµÄÌìÊý£¬¿ÉÒÔʹÓÓһÄêµÄÈÕÊý”£¨“y”£©»ò“ÈÕ”£¨“d”£©¡£µ± inter


Ïà¹ØÎĵµ£º

SQLSERVER´óÅúÁ¿Êý¾Ý²Ù×÷ʱËùÕ¼ÓÃÄÚ´æÊÍ...

ÏÖÏó£º
ÏÖÔÚ×öÒ»¸ö³ÌÐò£¬¶ÔÊý¾Ý¿âµÄ¼¸¸ö×°ÓдóÁ¿Êý¾ÝµÄ±í½øÐвÙ×÷£¬¶ÔÆäÖеÄÒ»¸ö±í½øÐÐ
Ñ­»·²Ù×÷£¬ÒÔ´¦ÀíÆäËûµÄ¼¸¸ö±í¡£ÆäÖÐÓõ½Á˼¸¸öquery,update£¬µ±³ÌÐòÅܵĹý³ÌÖУ¬
SQLSERVERµÄÄÚ´æ²»¶ÏµÄÔö³¤£¬ÅÜÍêºó¹Ø±Õ³ÌÐòÍ˳öºóÒ²²»½µÏÂÀ´¡£
½â¾ö£º
ÕâÊÇSQLµÄÄÚ´æ¹ÜÀí»úÖƾö¶¨µÄ£¬SQL¹ÜÀíÄÚ´æµÄÔ­ÔòÊÇÕâÑùµÄ,Ö»ÒªÄãµÄÄÚ´æ¹» ......

SQLServer ÖбíµÄ×ÔÔö³¤ÁÐ

1.½¨±í(Create table)ʱʹÓàIDENTITY (SEED,INCREMENT)
ÆäÖÐSEEDÊÇÆðʼֵ£¬INCREMENTÊÇÔöÁ¿¡£
Àý£º
CREATE TABLE mytable1
    (
      [user_id] BIGINT NOT NULL
                       IDENTITY(1, 1) , ......

MyEclipseÖÐÅäÖÃSQLServer 2005Êý¾Ý¿â

1.°²×°ºÃSQLServer 2005Êý¾Ý¿âÈí¼þ£¬½Ó×Å×îÖØÒªµÄ¾ÍÊÇ°²×°Êý¾Ý¿âÇý¶¯SQL Server 2005 driver for JDBC£¬¿ÉÒÔµ½:http://download.microsoft.com/download/8/B/D/8BDABAE2-B6EA-41D4-B903-7916EF3690EF/sqljdbc_1.2.2323.101_enu.exeÏÂÔØ
2.½«JDBC½âѹµ½ÈÎÒâµÄλÖã¬ÔÚ°²×°Ä¿Â¼ÀïÕÒµ½sqljdbc.jarÎļþ£¬ÒÔÇ°µÄÎÄÕÂÖÐÒѾ­½²¹ý» ......

ʹÓÃT SQL»ñÈ¡µ½SQLServer IpºÍ¶Ë¿ÚºÅ

ÔÚƽʱµÄ¹¤×÷¹ý³ÌÖУ¬×÷ΪDBA½ÇÉ«¹ÜÀíÊý¾Ý¿â£¬Í·ÄÔÖеÄÓ¡ÏóÍùÍùÊÇÊý¾Ý¿âʵÀýÃû³Æ£¬¶ø²»»áÈ¥¹ØÐÄServerµÄIP£¬¶ø×÷ΪDeveloperµÄ½ÇÉ«£¬ËûÃÇÍùÍùÏëÖªµÀÖªµÀServer IpºÍ¶Ë¿ÚºÅ¡£ËùÒÔ£¬DBA»á¾­³£±»Îʼ°µ½£ºXXXʵÀýµÄIPºÍ¶Ë¿ÚºÅÊÇʲô£¿
Õâ¸öÎÊÌ⣬µ±È»ÎÒÃÇ¿ÉÒÔLoginµ½OS²é¿´IP¡¢Ê¹ÓÃÅäÖƹÜÀí¹¤¾ß»ñÈ¡µ½¶Ë¿ÚºÅ¡£µ«ÊÇ£¬Õâ¸ö·½·¨·Ç ......

SQLServerÖÐÎÄ´¦Àí

Ê×ÏȲå¾äÌâÍâ»°£º´´½¨Ò»¸ö×ÔÈ»Êý±íNums¡£ÕâÊÇ¡¶SQL Server 2005¼¼ÊõÄÚÄ»£ºT-SQL²éѯ¡·Ò»ÊéµÄ½¨Òé¡£
ÔÚSQL Server 2005ÖУ¬¿ÉÒÔ½èÓÃROW_NUMBERÅÅÃûº¯ÊýÇáËÉÉú³ÉÎÒÃÇËùÐèµÄ×ÔÈ»Êý±í£º
--×ÔÈ»Êý±í1-1M
CREATE TABLE Nums(n int NOT NULL PRIMARY KEY CLUSTERED)
WITH B1 AS(SELECT n=1 UNION ALL SELECT n=1), --2
B2 AS( ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ