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

sql DATEPARTº¯ÊýʹÓÃ

sql DATEPARTº¯ÊýʹÓÃ(Õª³­)
sql DATEPARTº¯ÊýʹÓÃ
DATEPART
·µ»Ø´ú±íÖ¸¶¨ÈÕÆÚµÄÖ¸¶¨ÈÕÆÚ²¿·ÖµÄÕûÊý¡£
Óï·¨
DATEPART ( datepart ,date )
²ÎÊý
datepart
ÊÇÖ¸¶¨Ó¦·µ»ØµÄÈÕÆÚ²¿·ÖµÄ²ÎÊý¡£Ï±íÁгöÁË Microsoft® SQL Server™ ʶ±ðµÄÈÕÆÚ²¿·ÖºÍËõд¡£
ÈÕÆÚ²¿·ÖËõд
year
yy, yyyy
quarter
qq, q
month
mm, m
dayofyear
dy, y
day
dd, d
week
wk, ww
weekday
dw
Hour
hh
minute
mi, n
second
ss, s
millisecond
ms
week (wk, ww) ÈÕÆÚ²¿·Ö·´Ó³¶Ô SET DATEFIRST ×÷µÄ¸ü¸Ä¡£ÈκÎÒ»ÄêµÄ 1 Ô 1 ÈÕ¶¨ÒåÁË week ÈÕÆÚ²¿·ÖµÄ¿ªÊ¼Êý×Ö£¬ÀýÈ磺DATEPART(wk, 'Jan 1, xxxx') = 1£¬´Ë´¦ xxxx ´ú±íÈÎÒ»Äê¡£
weekday (dw) ÈÕÆÚ²¿·Ö·µ»Ø¶ÔÓ¦ÓÚÐÇÆÚÖеÄijÌìµÄÊý£¬ÀýÈ磺Sunday = 1¡¢Saturday = 7¡£weekday ÈÕÆÚ²¿·Ö²úÉúµÄÊýÈ¡¾öÓÚ SET DATEFIRST É趨µÄÖµ£¬´ËÃüÁîÉ趨ÐÇÆÚÖеĵÚÒ»Ìì¡£
date
ÊÇ·µ»Ø datetime »ò smalldatetime Öµ»òÈÕÆÚ¸ñʽ×Ö·û´®µÄ±í´ïʽ¡£¶Ô 1753 Äê 1 Ô 1 ÈÕÖ®ºóµÄÈÕÆÚÓÃdatetime Êý¾ÝÀàÐÍ¡£¸üÔçµÄÈÕÆڴ洢Ϊ×Ö·ûÊý¾Ý¡£µ±ÊäÈë datetime ֵʱ£¬Ê¼ÖÕ½«Æä·ÅÈëÒýºÅÖС£ÒòΪ smalldatetime Ö»¾«È·µ½·ÖÖÓ£¬ËùÒÔµ±Óà smalldatetime ֵʱ£¬ÃëºÍºÁÃë×ÜÊÇ 0¡£
Èç¹ûÖ»Ö¸¶¨Äê·ÝµÄ×îºóÁ½Î»Êý×Ö£¬ÔòСÓÚ»òµÈÓÚ"Á½Î»ÊýÄê·Ý½ØÖ¹ÆÚ"ÅäÖÃÑ¡ÏîµÄÖµµÄ×îºóÁ½Î»Êý×ÖµÄÊý×ÖËùÔÚÊÀ¼ÍÓë½ØÖ¹ÄêËùÔÚÊÀ¼ÍÏàͬ¡£´óÓÚ¸ÃÑ¡ÏîµÄÖµµÄ×îºóÁ½Î»Êý×ÖµÄÊý×ÖËùÔÚÊÀ¼ÍΪ½ØÖ¹ÄêËùÔÚÊÀ¼ÍµÄÇ°Ò»¸öÊÀ¼Í¡£ÀýÈ磬Èç¹û two digit year cutoff Ϊ 2049 £¨Ä¬ÈÏ£©£¬Ôò 49 ±»½âÊÍΪ 2049£¬2050 ±»½âÊÍΪ 1950¡£Îª±ÜÃâÄ£ºý£¬ÇëʹÓÃËÄλÊýµÄÄê·Ý¡£
ÓйØʱ¼äÖµÖ¸¶¨µÄ¸ü¶àÐÅÏ¢£¬Çë²Î¼ûʱ¼ä¸ñʽ¡£ÓйØÈÕÆÚÖ¸¶¨µÄ¸ü¶àÐÅÏ¢£¬Çë²Î¼û datetime ºÍ smalldatetime¡£
·µ»ØÀàÐÍ
int
×¢ÊÍ
DAY¡¢MONTH¡¢ºÍ YEAR º¯Êý·Ö±ðÊÇ DATEPART(dd, date)¡¢DATEPART(mm, date)¡¢ºÍ DATEPART(yy, date) µÄͬÒå´Ê¡£
ʾÀý
GETDATE º¯Êý·µ»Øµ±Ç°ÈÕÆÚ£»È»¶ø£¬±È½Ïʱ²¢²»×ÜÊÇÐèÒªÍêÕûµÄÈÕÆÚÐÅÏ¢£¨Í¨³£Ö»ÊǶÔÈÕÆÚµÄÒ»²¿·Ö½øÐбȽϣ©¡£´ËʾÀýÏÔʾ GETDATE ¼° DATEPART µÄÊä³ö¡£
SELECT GETDATE() AS 'Current Date'
GO
ÏÂÃæÊǽá¹û¼¯£º
Current Date
---------------------------
Feb 18 1998 11:46PM
SELECT DATEPART(month, GETDATE()) AS 'Month Number'
GO
ÏÂÃæÊǽá¹û¼¯£º
Month Number
------------
2
´ËʾÀý¼ÙÉèÈÕÆÚÊÇ 5 Ô 29 ÈÕ¡£
SELECT DATEPART(month, GETDA


Ïà¹ØÎĵµ£º

SQLµÄÇ°ÊÀ½ñÉú

 Ç°ÑÔÀÎÒ̸µ½ÁËһЩFORTRAN³ÌÐòÔ±ºÍÒ»ÃûLISP³ÌÐòÔ±µÄÊ£¬Ç°ÕßÖ»»áʹÓÃÑ­»·À´½â¾öÎÊÌ⣬ºóÕßÖ»»áʹÓõݹ鷽ʽ½â¾öÎÊÌâ¡£ÕâÖÖÇé¿ö²¢²»
ÉÙ¼û£¬ÒòΪÈËÃǶ¼Ï²»¶Ê¹ÓÃ×Ô¼ºÁ˽âµÄ¹¤¾ß¡£ÏÂÃæ½²Ò»¸öЦ»°£¬²»ÊÇÕæÊ£ºÓÐÈ˸øÒ»¸öÊýѧ¼Ò¡¢Ò»¸öÎïÀíѧ¼ÒºÍÒ»¸öÊý¾Ý¿â³ÌÐòÔ±¸÷·¢ÁËÒ»¸öÏðƤÇò£¬²¢ÇÒÈÃËûÃÇÈ·
¶¨ÇòµÄÌå»ý¡£
Êýѧ¼Ò ......

sql serverÊÓͼµÄ×÷Óã¨×ª£©

    ËùνÊÓͼ£¨View£©ÆäʵÊÇÖ´ÐвéѯÓï¾äºóµÃµ½µÄ½á¹û£¬µ«Õâ¸ö²éѯ½á¹û¿ÉÒÔ·ÂÕæ³ÉÊý¾Ý±íÀ´Ê¹Óã¬ËùÒÔÓÐÈËÒ²³ÆËüΪ“ÐéÄâÊý¾Ý±í”£¬ÊÓͼÔÚ²Ù×÷ÉϺÍÊý¾Ý±íûÓÐʲôÇø±ð£¬µ«Á½ÕߵIJîÒìÊÇÆä±¾ÖÊÊDz»Í¬µÄ£ºÊý¾Ý±íÊÇʵ¼Ê´æ´¢¼Ç¼µÄµØ·½£¬È»¶øÊÓͼ²¢²»±£´æÈκμǼ£¬Ëü´æ´¢µÄʵ¼ÊÉÏÊDzéѯÓï¾ä£¬ÆäËù³ÊÏÖ³ ......

caseÓï¾äÔÚSQLÖеÄʹÓ÷½·¨

Case¾ßÓÐÁ½ÖÖ¸ñʽ¡£¼òµ¥Caseº¯ÊýºÍCaseËÑË÷º¯Êý¡£
--¼òµ¥Caseº¯Êý
CASE sex
WHEN '1' THEN 'ÄÐ'
WHEN '2' THEN 'Å®'
ELSE 'ÆäËû' END
--CaseËÑË÷º¯Êý
CASE WHEN sex = '1' THEN 'ÄÐ'
WHEN sex = '2' THEN 'Å®'
ELSE 'ÆäËû' END
ÕâÁ½ÖÖ·½Ê½£¬¿ÉÒÔʵÏÖÏàͬµÄ¹¦ÄÜ¡£¼òµ¥Caseº¯ÊýµÄд·¨Ïà ......

Ö±½ÓÖ´ÐÐSQLÃüÁî

±êÇ©£ºÊý¾Ý·ÃÎÊ     ADO.NET
    Ö±½ÓÖ´ÐÐSQLÃüÁî     Ö´ÐÐÃæÏò¼¯ºÏµÄ²Ù×÷£¨ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ