SQL ²é¿´±¾ÖܵÄÐÇÆÚÒ»ºÍÐÇÆÚÌì
--SQL ²é¿´±¾ÖܵÄÐÇÆÚÒ»ºÍÐÇÆÚÌì
/*
ϵͳµÄʱ¼äĬÈÏ°ÑÐÇÆÚÌì×÷Ϊһ¸öÐÇÆڵĵÚÒ»Ì죬µ«ÊÇÎÒÃÇÖйúÏ°¹ß°ÑÐÇÆÚÒ»×÷Ϊһ¸öÐÇÆڵĵÚÒ»Ì죬Òò´ËÈç¹ûµ±ÌìÊÇÐÇÆÚÌìʱÐèÒªÅжÏÒ»ÏÂ
*/
DECLARE @MondayTime varchar(10)
DECLARE @SundayTime varchar(10)
IF(datepart(weekday,getdate())-2 < 0)
BEGIN
SET @MondayTime = convert(varchar(10),dateadd(dd,-1,getdate())-(datepart(weekday,dateadd(dd,-1,getdate()))-2),120)
SET @SundayTime = convert(varchar(10),dateadd(dd,-1,getdate())+(8-datepart(weekday,dateadd(dd,-1,getdate()))),120)
END
ELSE
BEGIN
SET @MondayTime =convert(varchar(10),getdate()-(datepart(weekday,getdate())-2),120)
SET @SundayTime =convert(varchar(10),getdate()+(8-datepart(weekday,getdate())),120)
END
SELECT @MondayTime as 'µÚÒ»Ìì(ÖÜÒ»)', @SundayTime as '×îºóÒ»Ìì(ÖÜÈÕ)'
--Ò²¿ÉÒÔÉèÖÃÿÖܵĵÚÒ»Ìì
ÉèÖÃÐÇÆÚһΪһÖܵĵÚÒ»Ìì
SET DATEFIRST ÉèÖÃÒ»ÖܵĵÚÒ»ÌìÊÇÐÇÆÚ¼¸£¬¸ÃÉèÖöÔËùÓÐÓû§¾ùÓÐЧ£¬³ý·ÇÔÙ´ÎÐ޸ģ¬·ñÔò¸ÃÉèÖý«Ò»Ö±±£Áô¡£
SET DATEFIRSTµÄ¾ßÌåÓï·¨ÈçÏ£º
SET DATEFIRST { number | @number_var }
ÆäÖвÎÊýnumber | @number_varÊÇÒ»¸öÕûÊý£¬±íʾһÖܵĵÚÒ»Ìì¡£ÔÊÐíµÄÖµÊÇ1¡«7£¬1±íʾһÖܵĵÚÒ»ÌìÊÇÐÇÆÚÒ»£¬7±íʾһÖܵĵÚÒ»Ìì¶ÔӦΪÐÇÆÚÈÕ¡£numberµÄĬÈÏÖµÊÇ7£¨¼´Ò»ÖܵĵÚÒ»ÌìΪÐÇÆÚÈÕ£©¡£¿ÉÒÔͨ¹ý²éѯϵͳ±äÁ¿@@DATEFIRST»ñÈ¡µ±Ç°µÄSET DATEFIRSTÉèÖÃÖµ¡£
DATENAME(dw,date)¼°DATEPART(dw,date)µÄ½á¹û»áÊܵ½SET DATEFIRSTÉèÖÃÖµµÄÓ°Ïì¡£
SET DATEFIRST 1
--Õâʱ²éÕÒ±¾ÖܵÄÊý¾Ý¾Í·½±ã¶àÁË
SELECT * from T_news WHERE (DATEPART(wk, addtime) = DATEPART(wk, GETDATE())) AND (DATEPART(yy, addtime) = DATEPART(yy, GETDATE()))
ÁíÍ⣺
Ò»Ìì "select * from T_news where datediff(day,addtime,getdate())=0";
ÈýÌì "select * from T_news where datediff(day,addtime,getdate())<= 2 and datediff(day,addtime,getdate())>= 0";
Ò»ÔÂ "SELECT * from T_news WHERE (DATEPART(yy, addtime) = DATEPART(yy, GETDATE())) AND (DATEPART(mm, addtime) = DATEPART(mm, GETDATE()))";
Ò»¼¾¶È "select * from t_news where DATEPART(qq, addtime) = DATEPART(qq, GETDATE()) and DATEPART(yy, a
Ïà¹ØÎĵµ£º
PL/SQL´æ´¢¹ý³Ì±à³Ì ÊÕ²Ø
/**author huangchaobiao
*Email:huangchaobiao111@163.com
*/
PL/SQL´æ´¢¹ý³Ì±à³Ì(ÉÏ)
1. OracleÓ¦Óñ༷½·¨¸ÅÀÀ
´ð£º1) Pro*C/C++/... : CÓïÑÔºÍÊý¾Ý¿â´ò½»µÀµÄ·½·¨£¬±ÈOCI¸ü³£ÓÃ;
2) ODBC
3) OCI: CÓïÑÔºÍÊý¾Ý¿â´ò½»µÀµÄ·½·¨£¬ºÍProCºÜÏàËÆ£¬¸üµ×²ã£¬ºÜÉÙÓÃ;
4) SQLJ ......
/******* µ¼³öµ½excel
exec master..xp_cmdshell ’bcp settledb.dbo.shanghu out c:\temp1.xls -c -q -s"gnetdata/gnetdata" -u"sa" -p""’
/*********** µ¼Èëexcel
select *
from opendatasource( ’microsoft.jet.oledb.4.0’,
’data source="c:\test.xls";user ......
SQL ServerÔÚ°²×°µ½·þÎñÆ÷ÉϺó£¬ÓÉÓÚ³öÓÚ·þÎñÆ÷°²È«µÄÐèÒª£¬ËùÒÔÐèÒªÆÁ±ÎµôËùÓв»Ê¹ÓõĶ˿ڣ¬Ö»¿ª·Å±ØÐëʹÓõĶ˿ڡ£ÏÂÃæ¾ÍÀ´½éÉÜÏÂSQL Server 2008ÖÐʹÓõĶ˿ÚÓÐÄÄЩ£º
Ê×ÏÈ£¬×î³£ÓÃ×î³£¼ûµÄ¾ÍÊÇ1433¶Ë¿Ú¡£Õâ¸öÊÇÊý¾Ý¿âÒýÇæµÄ¶Ë¿Ú£¬Èç¹ûÎÒÃÇÒªÔ¶³ÌÁ¬½ÓÊý¾Ý¿âÒýÇ棬ÄÇô¾ÍÐèÒª´ò¿ª¸Ã¶Ë¿Ú¡£Õâ¸ö¶Ë¿ÚÊÇ¿ÉÒÔÐ޸ĵģ¬ÔÚ&ldq ......
GROUP BY×Ó¾ä
Ö¸¶¨²éѯ½á¹ûµÄ·Ö×éÌõ¼þ
Óï·¨£ºGROUP BY [ALL] group_by_expression_r_r [,n]
[WITH{CUBE|ROLLUP}]
group_by_expression_r_rÖ¸Ã÷·Ö×éÌõ¼þ£¬Í¨³£ÊÇÒ»¸öÁÐÃû£¬µ«²»ÄÜÊÇÁеıðÃû¡£
ALL·µ»ØËùÓвéѯ½á¹ûµÄ×éºÏ¡£Èç¹ûûÓÐÂú×ãwhere×Ó¾äµÄÊý¾ÝÔòÓÉNULLÖµ¹¹³ÉÊý¾Ý¡£ALLµÄÑ¡Ïî²»Ä ......
Oracle SQL Developer ÊÇÒ»¸öÃâ·ÑµÄͼÐλ¯Êý¾Ý¿â¿ª·¢¹¤¾ß¡£Ê¹Óà SQL Developer£¬Äú¿ÉÒÔä¯ÀÀÊý¾Ý¿â¶ÔÏó¡¢ÔËÐÐ SQL Óï¾äºÍ SQL ½Å±¾£¬²¢ÇÒ»¹¿ÉÒԱ༺͵÷ÊÔ PL/SQL Óï¾ä¡£Äú»¹¿ÉÒÔÔËÐÐËùÌṩµÄÈκÎÊýÁ¿µÄ±¨±í£¬ÒÔ¼°´´½¨ºÍ±£´æÄú×Ô¼ºµÄ±¨±í¡£SQL Developer ¿ÉÒÔÌá¸ß¹¤×÷ЧÂʲ¢¼ò»¯Êý¾Ý¿â¿ª·¢ÈÎÎñ¡£
SQL Developer ¿ÉÒÔÁ¬½Óµ½È ......