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

SQL Server ÐÐÁÐת»»

ÔÚSQL SERVERÖУ¬ÓÐʱÐèÒªºÏ¶àÁÐÖµµ½ÐеÄÐèÇ󣬳£¼ûµÄ·½·¨ÓУº1.´´½¨×Ô¶¨Ò庯Êý£¬2.ʹÓÃÓα귨½øÐÐ×Ö·û´®ºÏ²¢¡£3.ʹÓÃÁÙʱ±íʵÏÖ×Ö·û´®ºÏ²¢¡£ Êý¾Ý£º DEPTNO EMPS
------ ----------
10 CLARK
10 KING
10 MILLER
20 SMITH
20 ADAMS
20 FORD
20 SCOTT
20 JONES
30 ALLEN
30 BLAKE
30 MARTIN
30 JAMES
30 TURNER
30 WARD
ÆÚÍû½á¹û£º
DEPTNO EMPS
------- ------------------------------------
10 CLARK,KING,MILLER
20 SMITH,JONES,SCOTT,ADAMS,FORD
30 ALLEN,WARD,MARTIN,BLAKE,TURNER,JAMES
1.xmloutput---------------------------------------
SELECT *
from(
SELECT DISTINCT
deptno
from emp
)A
OUTER APPLY(
SELECT
[values]= STUFF(REPLACE(REPLACE(
(
SELECT ENAME from emp N
WHERE deptno = A.deptno
FOR XML AUTO
), '', ''), 1, 1, '')
)N
 
2.---using CTE----------------------------------------
--Creating a Delimited List from Table Rows
-------------------------------------------------------
with x (deptno, cnt, list, empno, len)
as (
select deptno, count(*) over (partition by deptno),
cast(ename as varchar(100)),
empno,
1
from emp
union all
select x.deptno, x.cnt,
cast(x.list + ',' + e.ename as varchar(100)),
e.empno, x.len+1
from emp e, x
where e.deptno = x.deptno
and e.empno > x. empno
)
select deptno,list
from x
where len = cnt
order by 1
3.....


Ïà¹ØÎĵµ£º

PL/SQLÓαê±äÁ¿µÄµ÷ÓÃÓë×÷ΪÊä³ö²ÎÊýµÄÓ¦ÓÃ

      ½ñÌìÓиöѧÉúÎÊÎÒµ÷ÓðüÀïÃæ¾ßÓÐÓαêÀàÐ͵ÄÊä³ö²ÎÊý£¬¿ÉÊÇÔÚÓÃPL/SQL³ÌÐòµ÷ÓõÄʱºò¾ÓÈ»±¨³ö²ÎÊý¸öÊý»òÀàÐÍ´íÎóµÄÒì³£ÐÅÏ¢£¬ÓÚÊÇ×Ô¼ºÒ²ÊÔÁËһϣ¬¹ûÈ»Êdzö´íÁË¡£È»ºó¾Í×Ô¼º×ÁÄ¥ÁËһϡ¢²é²é×ÊÁϺÍÎÊÎÊͬÊ£¬Ô­À´ÎÊÌâÊǺܼòµ¥µÄ£¬ÏÈ¿´Ò»Ï³ÌÐòµÄ½á¹¹´úÂ룺
CREATE OR REPLACE PACKAGE Pkg_S ......

SQL Server 2005 ¾µÏñ¹¹½¨ÊÖ²á

Ò»¡¢ ¾µÏñ¼ò½é
1¡¢ ¼ò½é
Êý¾Ý¿â¾µÏñÊǽ«Êý¾Ý¿âÊÂÎñ´¦Àí´ÓÒ»¸öSQL ServerÊý¾Ý¿âÒƶ¯µ½²»Í¬SQL Server»·¾³ÖеÄÁíÒ»¸öSQL ServerÊý¾Ý¿âÖС£¾µÏñ²»ÄÜÖ±½Ó·ÃÎÊ;ËüÖ»ÓÃÔÚ´íÎó»Ö¸´µÄÇé¿öϲſÉÒÔ±»·ÃÎÊ¡£
Òª½øÐÐÊý¾Ý¿â¾µÏñËùÐèµÄ×îСÐèÇó°üÀ¨ÁËÁ½¸ö²»Í¬µÄSQL ServerÔËÐл·¾³¡£Ö÷·þÎñÆ÷±»³ÆΪ“Ö÷»ú”£¬µÚ¶þ¸ö·þÎñÆ÷±» ......

Sql Server Êý¾Ý¿âÁ¬½ÓÎÊÌâ

²Î¿¼ÎÄÏ×£ºhttp://www.cnblogs.com/chenxizhang/archive/2009/04/23/1441913.html
SQL ServerÌṩËÄÖÖ·½Ê½Á¬½ÓÊý¾Ý¿â·þÎñÆ÷:
1. share memory: Ö»ÊÊÓÃÓÚ¿Í»§¶ËºÍ·þÎñÆ÷¶ËÔÚͬһ̨»úÆ÷ÉÏ,²ÅÄܲÉÓõÄÁ¬½Ó
2. Named pipe:
ÔÚ¾ÖÓòÍø(LAN)ÄÚʵÏÖÁ¬½Ó,Ò»¸ö½ø³ÌʹÓÃÒ»²¿·ÖµÄÄÚ´æÀ´Ïò½ø³ÌµÄÁíÒ»¶Ë´«µÝÏûÏ¢,Ò»¸ö½ø³ÌµÄÊä³öÊÇÁíÍâ ......

SQL Server²éѯһÖÜÄڵļǼ

select * from tableName where datediff(week,dateField,getdate())=0
ÕâÑù²é³öÀ´µÄ½á¹ûÊÇ´ÓÐÇÆÚÌìµ½ÐÇÆÚÁù(ÀÏÍâĬÈÏÐÇÆÚÌìÊÇÒ»ÖܵĵÚÒ»Ìì).
Èç¹ûÏëÒÔÐÇÆÚÒ»×÷ΪµÚÒ»ÌìµÄ»°,Á½¸öʱ¼ä¶¼ÐèÒª¼õÒ»,ÈçÏÂ:
select * from tableName where datediff(week,dateField-1,getdate()-1)=0 ......

sql ÓαêµÄ»ù±¾Ó÷¨

1. ¶¨ÒåÓα궨Òå
ÓαêÓï¾äµÄºËÐÄÊǶ¨ÒåÁËÒ»¸öÓαê±êʶÃû£¬²¢°ÑÓαê±êʶÃûºÍÒ»¸ö²éѯÓï¾ä¹ØÁªÆðÀ´¡£DECLAREÓï¾äÓÃÓÚÉùÃ÷Óα꣬Ëüͨ¹ýSELECT²éѯ¶¨ÒåÓαê´æ´¢µÄÊý¾Ý¼¯ºÏ¡£Óï¾ä¸ñʽΪ£º
DECLARE ÓαêÃû³Æ [INSENSITIVE] [SCROLL]
CURSOR FOR selectÓï¾ä
[FOR{READ ONLY|UPDATE[OF ÁÐÃû×Ö±í]}]
²ÎÊý˵Ã÷£º
INSENSITIVEÑ¡Ï ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ