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

SQL DateTime²éѯÓë¸ñʽ

select * from orders where month(orderdate)= (select month(orderdate) from orders where orderid=10248)
1.Ò»¸öÔµÚÒ»ÌìµÄ
Select DATEADD(mm, DATEDIFF(mm,0,getdate()), 0)
2.±¾ÖܵÄÐÇÆÚÒ»
Select DATEADD(wk, DATEDIFF(wk,0,getdate()), 0)
3.Ò»ÄêµÄµÚÒ»Ìì
Select DATEADD(yy, DATEDIFF(yy,0,getdate()), 0)
4.¼¾¶ÈµÄµÚÒ»Ìì
Select DATEADD(qq, DATEDIFF(qq,0,getdate()), 0)
5.µ±ÌìµÄ°ëÒ¹
Select DATEADD(dd, DATEDIFF(dd,0,getdate()), 0)
6.ÉϸöÔµÄ×îºóÒ»Ìì
Select dateadd(ms,-3,DATEADD(mm, DATEDIFF(mm,0,getdate()), 0))
7.È¥ÄêµÄ×îºóÒ»Ìì
Select dateadd(ms,-3,DATEADD(yy, DATEDIFF(yy,0,getdate()), 0))
8.±¾ÔµÄ×îºóÒ»Ìì
Select dateadd(ms,-3,DATEADD(mm, DATEDIFF(m,0,getdate())+1, 0))
9.±¾ÄêµÄ×îºóÒ»Ìì
Select dateadd(ms,-3,DATEADD(yy, DATEDIFF(yy,0,getdate())+1, 0))
10.±¾ÔµĵÚÒ»¸öÐÇÆÚÒ»
select DATEADD(wk, DATEDIFF(wk,0,dateadd(dd,6-datepart(day,getdate()),getdate())), 0)
·µ»Øµ±Ç°ÈÕÆÚºÍʱ¼ä
ͨ¹ýº¯ÊýGETDATE£¨£©£¬Äã¿ÉÒÔ»ñµÃµ±Ç°µÄÈÕÆÚºÍʱ¼ä¡£º¯ÊýGETDATE£¨£©¿ÉÒÔÓÃÀ´×÷ΪDATEDIMEÐÍ×ֶεÄȱʡֵ¡£Õâ¶Ô²åÈë¼Ç¼ʱ±£´æµ±Ê±µÄʱ¼äÊÇÓÐÓõġ£Òª½¨Á¢Ò»¸ö±í£¬ÆäÖеļǼ°üº¬Óе±Ç°µÄÈÕÆÚºÍʱ¼ä£¬¿ÉÒÔÌí¼ÓÒ»¸öDATETIMEÐÍ×ֶΣ¬Ö¸¶¨ÆäȱʡֵΪº¯ÊýGETDATE£¨£©µÄ·µ»ØÖµ£¬¾ÍÏóÕâÑù£º
Create TABLE site_log (
username VARCHAR(40)£¬
useractivity VARCHAR(100)£¬
entrydate DATETIME DEFAULT GETDATE())
ת»»ÈÕÆÚºÍʱ¼ä
º¯ÊýGETDATE£¨£©µÄ·µ»ØÖµÔÚÏÔʾʱֻÏÔʾµ½Ã롣ʵ¼ÊÉÏ£¬SQL SeverÄÚ²¿Ê±¼ä¿ÉÒÔ¾«È·µ½ºÁÃ뼶£¨È·ÇеØ˵£¬¿ÉÒÔ¾«È·µ½3.33ºÁÃ룩¡£
ÒªµÃµ½²»Í¬¸ñʽµÄÈÕÆÚºÍʱ¼ä£¬ÄãÐèҪʹÓú¯ÊýCONVERT£¨£©¡£ÀýÈ磬µ±ÏÂÃæµÄÕâ¸öÓï¾äÖ´ÐÐʱ£¬ÏÔʾµÄʱ¼ä½«°üÀ¨ºÁÃ룺
Select CONVERT(VARCHAR(30)£¬GETDATE()£¬9)
×¢ÒâÀý×ÓÖÐÊý×Ö9µÄʹÓá£Õâ¸öÊý×ÖÖ¸Ã÷ÁËÔÚÏÔʾÈÕÆÚºÍʱ¼äʱʹÓÃÄÄÖÖÈÕÆÚºÍʱ¼ä¸ñʽ¡£µ±Õâ¸öÓï¾äÖ´ÐÐʱ£¬½«ÏÔʾÈçϵÄÈÕÆÚºÍʱ¼ä£º
Nov 30 1997 3:29:55:170AM
(1 row(s) affected)
ÔÚº¯ÊýCONVERT£¨£©ÖÐÄã¿ÉÒÔʹÓÃÐí¶àÖÖ²»Í¬·ç¸ñµÄÈÕÆÚºÍʱ¼ä¸ñʽ¡£Ï±íÏÔʾÁËËùÓеĸñʽ¡£
ÈÕÆÚºÍʱ¼äµÄÀàÐÍ£º
ÀàÐÍÖµ ±ê×¼ Êä³ö
0 Default mon dd yyyy hh:miAM
1 USA mm/dd/yy
2 ANSI yy.mm.dd
3 British/French dd/mm/yy
4 German dd.mm.yy
5 Italian dd-mm-yy
6 - dd mon yy


Ïà¹ØÎĵµ£º

Êý¾Ý¿âÉè¼Æ£¨6£©_ÃüÃû¼°±àÂë¹æ·¶_SQL SERVER

Ò»¡¢×ÛÊö
ÃüÃûºÍ±àÂë¹ý³ÌÖУ¬¶¨ÒåÓÐÒâÒåµÄÃû³Æ£¬ÒÔÒ×ÓÚÀí½â¡¢·½±ãÊéдΪԭÔò¡£
£¨1£©±ÜÃâʹÓÃÖÐÎÄ£¬¾¡Á¿Ê¹ÓÃÈ«Æ´Òô»òÈ«Ó¢ÎÄ£¬ÒÔ·½±ã¹ú¼Ê»¯£»
£¨2£©±ÜÃâÆ´ÒôºÍÓ¢ÎĵÄÖÐÎ÷ºÏèµ£¬È磺CAOZUO_TIME£»
£¨3£©±ÜÃâÔÚÃüÃûÖаüÀ¨¿Õ¸ñ¼°ÌØÊâ×Ö·û£»
£¨4£©±ÜÃâʹÓñ£Áô×Ö£»
£¨5£©±ÜÃâÃû³ÆÌ«³¤£¬×¢ÒâËõдµÄʹÓã¬Ëõд¹æÔòΪµ¥´ÊÇ°4¸ ......

SQL Óï¾ä ¼ò½é

×î½üÁ½ÌìÒ»Ö±ÔÚÕÛÌÚSQLÓï¾ä£¬Ã»°ì·¨£¬Ð´Êý¾Ý¿âµÄÐֵܸøÁËÁ½¸öÀý×ӾͲ»ÔÙ¹ÜÁË£¬¶øÇÒ×î½üÇë¼ÙÁË¡£½ñÌì¼Ó°à»¹ÊÇÕÛÌÚÕâôһ¸öÓï¾ä£¬×ÜÊDz»¶Ô£¬ÇëÀÏ´ó¿´ÁË¿´»¹ÊÇû¿´³öÃŵÀÀ´£¬ ÔÚSQLite Expert Professional ÀïÃæдµÄÓï¾ä¶¼¿ÉÒÔÖ´Ðгɹ¦£¬µ«ÊÇÔÚAndroidµÄ¹¤³ÌÀïÃæÔõôÕÛÌھͲ»¶Ô¡£ ÓôÃÆ°¡£¬½ñÌì¼Ó°àËãÊÇ°×¼ÓÁË¡£
ΪÁ˲éÕÒºÍÑ§Ï ......

ʹÓÃSQLÓï¾äÆô¶¯SQL ServerÍâΧ×é¼þ·þÎñ

-- To allow advanced options to be changed.
EXEC sp_configure 'show advanced options', 1
GO
-- To update the currently configured value for advanced options.
RECONFIGURE
GO
-- To enable the feature.
EXEC sp_configure 'CLR', 0
GO
-- To update the currently configured value for this feature. ......

ÔÚSQL ServerÖÐÓÃXQuery·Ö½âXMLÊý¾Ý

¡¡¡¡±¾ÎÄÌÖÂÛSQL Server 2005µÄй¦ÄÜ£¬ËüÔÊÐíÄ㽫XMLÊý¾Ý·Ö½âµ½¹Øϵ¸ñʽÖУ¬¶ø²»±ØºÄÓÃÌ«¶àÄÚ´æ¡£
¡¡¡¡±¾ÎÄÌÖÂÛSQL Server 2005µÄй¦ÄÜ£¬ËüÔÊÐíÄ㽫XMLÊý¾Ý·Ö½âµ½¹Øϵ¸ñʽÖУ¬¶ø²»±ØºÄÓÃÌ«¶àÄÚ´æ¡£
¡¡¡¡ÔÚ¾ÙÀý˵Ã÷ÈçºÎ·Ö½âÉÏһƪÎÄÕÂÖеÄÊý¾Ýʱ£¬ÎÒÃÇÊ×ÏÈÁ˽âÒ»ÏÂXQueryºÍËüÔÚSQL Server 2005ÖÐΪ¿ª·¢ÕßÌṩµÄ¹¦ÄÜ¡£
¡ ......

д³ö¸ßÐÔÄÜSQLÓï¾äµÄ35Ìõ·½·¨·ÖÎö

¡¡¡¡(1)ÕûºÏ¼òµ¥,ÎÞ¹ØÁªµÄÊý¾Ý¿â·ÃÎÊ£º
¡¡¡¡Èç¹ûÄãÓм¸¸ö¼òµ¥µÄÊý¾Ý¿â²éѯÓï¾ä,Äã¿ÉÒÔ°ÑËüÃÇÕûºÏµ½Ò»¸ö²éѯÖÐ(¼´Ê¹ËüÃÇÖ®¼äûÓйØϵ)
¡¡¡¡(2)ɾ³ýÖظ´¼Ç¼£º
¡¡¡¡×î¸ßЧµÄɾ³ýÖظ´¼Ç¼·½·¨ ( ÒòΪʹÓÃÁËROWID)Àý×Ó£º
¡¡¡¡DELETE from EMP E WHERE E.ROWID > (SELECT MIN(X. ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ