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

SQL Server 2005 CTEµÄÓ÷¨

if object_id('[tb]') is not null
drop table [tb] 
go
create table [tb]([id] int,[col1] varchar(8),[col2] int) 
insert [tb] 
select 1,'ºÓ±±Ê¡',0 union all
 select 2,'ÐĮ̈ÊÐ',1 union all
 select 3,'ʯ¼ÒׯÊÐ',1 union all
 select 4,'ÕżҿÚÊÐ',1 union all
 select 5,'ÄϹ¬',2 union all 
select 6,'°ÓÉÏ',4 union all
  select 7,'ÈÎÏØ',2 union all
 select 8,'ÇåºÓ',2 union all 
select 9,'ºÓÄÏÊ¡',0 union all
 select 10,'ÐÂÏçÊÐ',9 union all
 select 11,'aaa',10 union all
 select 12,'bbb',10  
 
 ;with t as( 
select * from [tb] where col1='ºÓ±±Ê¡'  union all  select a.* from [tb] a  ,t where a.col2=t.id   
)
 
 select * from t


Ïà¹ØÎĵµ£º

bulletedlist ¼Ó sql server ²É¼¯ÍøÕ¾µØÖ·

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{ ......

Sql Server ²éѯsqlÖ´Ðи÷¸ö½×¶ÎµÄʱ¼ä

Sql Server ²éѯsqlÖ´Ðи÷¸ö½×¶ÎµÄʱ¼ä
set statistics io on
set statistics time on
set statistics profile on
go
[ÄãµÄsqlÓï¾ä]
go
set statistics io off
set statistics time off
set statistics profile off

ÎÒÔËÐУº
set statistics io on
set statistics time on
set statistics profile on ......

Sql½ØÈ¡×Ö·û

 ×öÏîÄ¿ÀïÃæµÄÊý¾Ý¿âÉè¼ÆÁËÁ½¸öÀàÐÍ·ÅÒ»¸ö×Ö¶ÎÀïÃæ,ÎÒÓÖҪͨ¹ý·Ö¿ªµÄÀàÐÍÀ´½øÐвéѯ,Í´¿à°¡,
Á½ÖÖ·½·¨;
1,¶ÁÈ¡µ½»º´æÖÐ×Ô¶¨Òådatatable, ´úÂë¾Í²»ÌùÁË.
²»ÐÀÉÍÕâÖÖ×ö·¨,ÒòΪÎÒÒѾ­°ÑÒ³ÃæÉϺܶණÎ÷дÁË,¶¼ÊÇÓеÄSqlÓï¾ä,ÕâÑù¸Äһ϶¼Òª¸ÄÁË.
2.Ö±½ÓÔÚSqlÀïÃæ½¨ÊÓͼ,
lÓÃSUBSTRING(dbo.K_ProductDtl.Caizhi, 0, CH ......

sql convertÈÕÆÚʱ¼ä¸ñʽ

--²éѯÏÖÔÚÈÕÆÚ£¬Ö»ÒªÄêÔÂÈÕ
 select convert(varchar(10),getDate(),120)
--²éѯÏÖÔÚÈÕÆÚ£¬Ö»ÒªÊ±·ÖÃë
select convert(varchar(8),getDate(),8)
Convertº¯ÊýµÄһЩ˵Ã÷£¬ÒÔÏÂ×ÊÁÏÀ´Ô´ÓÚÍøÂç
²»´øÊÀ¼ÍÊýλ (yy)
´øÊÀ¼ÍÊýλ (yyyy)

±ê×¼

ÊäÈë ......

35Ìõ»ù±¾SQLÓï¾ä

 1¡¢²éÕÒÔ±¹¤µÄ±àºÅ¡¢ÐÕÃû¡¢²¿ÃźͳöÉúÈÕÆÚ£¬Èç¹û³öÉúÈÕÆÚΪ¿ÕÖµ£¬ÏÔʾÈÕÆÚ²»Ïê,²¢°´²¿ÃÅÅÅÐòÊä³ö,ÈÕÆÚ¸ñʽΪyyyy-mm-dd¡£
select
emp_no,emp_name,dept,isnull(convert(char(10),birthday,120),'ÈÕÆÚ²»Ïê') birthday
from employee
order by dept
 
¡¡¡¡
2¡¢²éÕÒÓëÓ÷×ÔÇ¿ÔÚͬһ¸öµ¥Î»µÄÔ±¹¤ÐÕÃû¡¢ÐÔ±ð¡ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ