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

sqlserver×Ö·û´®ºÏ²¢(merge)·½·¨»ã×Ü

ÎÞÂÛÊÇÔÚsql 2000£¬»¹ÊÇÔÚ sql 2005 ÖÐ,¶¼Ã»ÓÐÌṩ×Ö·û´®µÄ¾ÛºÏº¯Êý£¬ËùÒÔ£¬µ±ÎÒÃÇÔÚ´¦ÀíÏÂÁÐÒªÇóʱ£¬»á±È½ÏÂé·³£ºÓбítb, ÈçÏ£ºid value----- ------1 aa1 bb2 aaa2 bbb2 cccÐèÒªµÃµ½½á¹û£ºid values------ -----------1 aa,bb2 aaa,bbb,ccc¼´£¬ group by id, Çó value µÄºÍ£¨×Ö·û´®Ïà¼Ó£© 1. ¾ÉµÄ½â¾ö·½·¨-- 1. ´´½¨´¦Àíº¯ÊýCREATE FUNCTION dbo.f_str(@id int)RETURNS varchar(8000)ASBEGINDECLARE @r varchar(8000)SET @r = ''SELECT @r = @r + ',' + valuefrom tbWHERE id=@idRETURN STUFF(@r, 1, 1, '')ENDGO-- µ÷Óú¯Êý SELECt id, values=dbo.f_str(id)from tbGROUP BY id -- 2.1 еĽâ¾ö·½·¨-- ʾÀýÊý¾ÝDECLARE @t TABLE(id int, value varchar(10))INSERT @t SELECT 1, 'aa'UNION ALL SELECT 1, 'bb'UNION ALL SELECT 2, 'aaa'UNION ALL SELECT 2, 'bbb'UNION ALL SELECT 2, 'ccc' -- ²éѯ´¦ÀíSELECT *from(SELECT DISTINCTidfrom @t)AOUTER APPLY(SELECT[values]= STUFF(REPLACE(REPLACE((SELECT value from @t NWHERE id = A.idFOR XML AUTO), '', ''), 1, 1, ''))N /*--½á¹ûid values----------- ----------------1 aa,bb2 aaa,bbb,ccc(2 ÐÐÊÜÓ°Ïì)--*/--2.2DECLARE @TB TABLE([Name] VARCHAR(1), [Value] VARCHAR(6))INSERT @TBSELECT 'A', '123' UNION ALLSELECT 'A', '677' UNION ALLSELECT 'B', 'HHDA' UNION ALLSELECT 'B', 'JYUKY' UNION ALLSELECT 'B', 'WRWFCW' UNION ALLSELECT 'B', 'YUYUY' UNION ALLSELECT 'C', 'TRREER' SELECT [Name],STUFF((SELECT ','+[Value] from @TB WHERE NAME=A.NAME FOR XML PATH('')),1,1,'') AS [Value]from @TB AS AGROUP BY [Name]/*Name Value---- ------------------------------------------A 123,677B HHDA,JYUKY,WRWFCW,YUYUYC TRREER*/ --¸÷ÖÖ×Ö·û´®·Öº¯Êý --3.3.1 ʹÓÃÓα귨½øÐÐ×Ö·û´®ºÏ²¢´¦ÀíµÄʾÀý¡£--´¦ÀíµÄÊý¾ÝCREATE TABLE tb(col1 varchar(10),col2 int)INSERT tb SELECT 'a',1UNION ALL SELECT 'a',2UNION ALL SELECT 'b',1UNION ALL SELECT 'b',2UNION ALL SELECT 'b',3 --ºÏ²¢´¦Àí--¶¨Òå½á¹û¼¯±í±äÁ¿DECLARE @t TABLE(col1 varchar(10),col2 varchar(100)) --¶¨ÒåÓα겢½øÐкϲ¢´¦ÀíDECLARE tb CURSOR LOCALFORSELECT col1,col2 from tb ORDER BY col1,col2DECLARE @col1_old varchar(10),@col1 varchar(10),@col2 int,@s varchar(100)OPEN tbFETCH tb INTO @col1,@col2SE


Ïà¹ØÎĵµ£º

oracleºÍsqlserver²éѯʱ×èÈûÇé¿ö

1.oracle»·¾³
create table test
(
id number(4),
name varchar2(20)
)
ÔÚÒ»¸ösessionÖÐ
insert into test values(1,'aa');
ÔÚÁíÒ»¸ösessionÖÐ
select * from test1;
²éѯû±»×èÈû
2.sqlserver»·¾³
ÔÚÒ»¸ösessionÖÐ
insert into test values(1,'aa');
ÔÚÁíÒ»¸ösessionÖÐ
select * from test1;
²éѯ±»×èÈû(Ê ......

sqlserver²éѯ£¨Ê±¼äÏà¹Ø£©

select a.UserName Óû§Ãû,b.LoginName ºÅÂë,c.MenuTitle ±êÌâ,max(a.AccessTime)·ÃÎÊʱ¼ä  from JfAccessLog a,OaUser b,JfMenu c where CONVERT(char,a.AccessTime,112)=CONVERT(char,GETDATE(),112)  and a.UserId=b.UserId and a.MenuId=c.MenuId and a.MenuId=@menu group by a.UserName,b.LoginName,c.Menu ......

ʹÓÃT SQL»ñÈ¡µ½SQLServer IpºÍ¶Ë¿ÚºÅ

ÔÚƽʱµÄ¹¤×÷¹ý³ÌÖУ¬×÷ΪDBA½ÇÉ«¹ÜÀíÊý¾Ý¿â£¬Í·ÄÔÖеÄÓ¡ÏóÍùÍùÊÇÊý¾Ý¿âʵÀýÃû³Æ£¬¶ø²»»áÈ¥¹ØÐÄServerµÄIP£¬¶ø×÷ΪDeveloperµÄ½ÇÉ«£¬ËûÃÇÍùÍùÏëÖªµÀÖªµÀServer IpºÍ¶Ë¿ÚºÅ¡£ËùÒÔ£¬DBA»á¾­³£±»Îʼ°µ½£ºXXXʵÀýµÄIPºÍ¶Ë¿ÚºÅÊÇʲô£¿
Õâ¸öÎÊÌ⣬µ±È»ÎÒÃÇ¿ÉÒÔLoginµ½OS²é¿´IP¡¢Ê¹ÓÃÅäÖƹÜÀí¹¤¾ß»ñÈ¡µ½¶Ë¿ÚºÅ¡£µ«ÊÇ£¬Õâ¸ö·½·¨·Ç ......

c#ÖиßЧµÄexcelµ¼ÈësqlserverµÄ·½·¨

±¾ÎÄת×Ô£ºhttp://blog.csdn.net/jinjazz/archive/2008/07/14/2650506.aspx
    ½«oledb¶ÁÈ¡µÄexcelÊý¾Ý¿ìËÙ²åÈëµÄsqlserverÖУ¬ºÜ¶àÈËͨ¹ýÑ­»·À´Æ´½Ósql£¬ÕâÑù×ö²»µ«ÈÝÒ׳ö´í¶øÇÒЧÂʵÍÏ£¬×îºÃµÄ°ì·¨ÊÇʹÓÃbcp£¬Ò²¾ÍÊÇSystem.Data.SqlClient.SqlBulkCopy ÀàÀ´ÊµÏÖ¡£²»µ«Ëٶȿ죬¶øÇÒ´úÂë¼òµ¥£¬ÏÂÃæ²âÊÔ´ú ......

javaÁ¬½Ósqlserver2005Êý¾Ý¿âÐĵÃÌå»á

sqlserverÊý¾Ý¿â£ºjavaÁ¬½Ósqlserver2005Êý¾Ý¿âÐĵÃÌå»á 
Ê×ÏȵÃÏÂÔØÇý¶¯³ÌÐòµ½Î¢ÈíÍøÕ¾ÏÂÔØMicrosoft SQL Server 2005 JDBC Driver 1.2¡¡¡¡½âѹMicrosoft SQL Server 2005 jdbc driver1.2.exe 
µÃµ½sqljdbc.jar£¬ÓõÃʱºòÖ±½Ó¼Óµ½classpathÖÐÈ¥. 
¡¡ÉèÖÃSQL Server·þÎñÆ÷ 
·ÀÖ¹³öÏÖ 
com.mi ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ