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

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


Ïà¹ØÎĵµ£º

SQL server2000¼ò½é

ÉÏÍøÒ»²é£¬SQL server2008¶¼³öÀ´ÁË£¬ÎÒ»¹ÊÇÏÈ´Ó»ù´¡µÄѧÆð°É¡£
SQL server2000µÄ³£¼û°æ±¾ÓУºÆóÒµ°æ¡¢±ê×¼°æ¡¢¸öÈ˰桢¿ª·¢°æ¡£
ÆóÒµ°æ£º¹¦ÄÜÈ«Ãæ£¬Ó¦ÓÃÓÚ´óÖÐÐͲúÆ··þÎñ´¦ÀíÆ÷£¬Ö§³Ö´óÐÍÍøÕ¾¡¢Áª»úÊÂÎñ´¦Àí£¬Áª»ú·ÖÎö´¦ÀíµÄÐÔÄÜ¡£
±ê×¼°æ£ºÊÊÓÃÓÚСÐ͹¤×÷×飬²»Ö§³Ö´óÐÍÊý¾Ý¿â£¬Êý¾Ý²Ö¿âºÍÍøÕ¾µÄ¹¦ÄÜ£¬¶øÇÒ²»Ö§³ÖËùÓÐ¹Ø ......

sql serverµ¥±íµ¼Èë¡¢µ¼³ö£¨Í¨¹ýCSVÎļþ£©


µ¼³ö£º
Ö±½Ó´ò¿ª²éѯ·ÖÎöÆ÷²éѯҪµ¼³ö±íµÄÐÅÏ¢£¨select *  from ±í£©£¬µÃµ½µÄ½á¹ûȫѡ£¬ÓÒ¼üÁí´æÎª xxx.csvÎļþ  £¨µÃµ½¸Ã±íµÄËùÓÐÐÅÏ¢£¬CSVÎļþ¸ñʽ£©
µ¼È룺
Ê×ÏÈͨ¹ýsql server µÄÆóÒµ¹ÜÀíÆ÷Éú³ÉÒªµ¼³ö±íµÄ SQL½Å±¾£¬²½Ö裺Ҫµ¼³ö±í——ËùÓÐÈÎÎñ£¨ÓÒ¼ü£©——Éú³ÉSQL½Å±¾
µÃµ½¸Ã±íµÄ ......

SQLÓïÑÔ»ù´¡£¨3£©

GROUP BY×Ó¾ä
Ö¸¶¨²éѯ½á¹ûµÄ·Ö×éÌõ¼þ
Óï·¨£ºGROUP BY [ALL] group_by_expression_r_r [,n]
      [WITH{CUBE|ROLLUP}]
group_by_expression_r_rÖ¸Ã÷·Ö×éÌõ¼þ£¬Í¨³£ÊÇÒ»¸öÁÐÃû£¬µ«²»ÄÜÊÇÁеıðÃû¡£
ALL·µ»ØËùÓвéѯ½á¹ûµÄ×éºÏ¡£Èç¹ûûÓÐÂú×ãwhere×Ó¾äµÄÊý¾ÝÔòÓÉNULLÖµ¹¹³ÉÊý¾Ý¡£ALLµÄÑ¡Ïî²»Ä ......

sql serverÖеÄconvertÈÕÆÚ¸ñʽ»¯´óÈ«

CONVERT
½«Ä³ÖÖÊý¾ÝÀàÐ͵ıí´ïʽÏÔʽת»»ÎªÁíÒ»ÖÖÊý¾ÝÀàÐÍ¡£ÓÉÓÚijЩÐèÇó¾­³£Óõ½È¡ÈÕÆÚ¸ñʽµÄ²»Í¬.ÏÖÒÔÏ¿ÉÔÚ
SQL ServerÖС¡½«ÈÕÆÚ¸ñʽ»¯.
SQL Server Ö§³ÖʹÓÿÆÍþÌØËã·¨µÄ°¢À­²®ÑùʽÖеÄÊý¾Ý¸ñʽ¡£
ÔÚ±íÖУ¬×ó²àµÄÁ½Áбíʾ½« datetime »ò smalldatetime ת»»Îª×Ö·ûÊý¾ÝµÄ style Öµ¡£¸ø style Öµ¼Ó 100£¬¿É»ñµÃ°üÀ¨Ê ......

SQLÖеĺ¯Êý

sqlÖеÄindexof£¬º¯Êý½éÉÜ
È¡³öÎļþÃûÖеĺó׺Ãû£¬ÀýÈ磺1.exe±ä³Éexe
declare @fileName varchar(100)
set @fileName='aaa.exe'
select substring(@fileName,charindex('.',@fileName)+1,len(@fileName))
------------------------------------------------
--×Ô¶¨Ò庯Êý£ºÈ¡ÎļþÃûµÄÎļþÀàÐÍ£¬ÀýÈç1.exeµÄexe
--- ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ