Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB
ÈÈÃűêÇ©£º c c# c++ asp asp.net linux php jsp java vb Python Ruby mysql sql access Sqlite sqlserver delphi javascript Oracle ajax wap mssql html css flash flex dreamweaver xml
 ×îÐÂÎÄÕ : sql

SQLµÝ¹é²éѯº¯Êý

--²éѯ¸¸µ¥Î»µÄº¯Êý
CREATE Function GetParentUnit(@UnitId bigint, @Level int) 
Returns @Parents Table([UnitId] int ,[UnitName] nvarchar(64),[ParentUnitId] int) 
As 
Begin
    If @Level < 1   --Èç¹û²ÎÊý@LevelСÓÚ“1”£¬ÔòµÃµ½ËùÓи¸µ¥Î»
        Begin        
            Insert @Parents 
                Select UnitId,UnitName,ParentUnitId 
                from [T_Unit] 
                Where [UnitId] = (Select [ParentUnitId]&nb ......

SQL Server Ë÷Òý½á¹¹¼°ÆäʹÓã¨Ò»£©

SQL Server Ë÷Òý½á¹¹¼°ÆäʹÓã¨Ò»£©
Ò»¡¢ÉîÈëdz³öÀí½âË÷Òý½á¹¹
¡¡¡¡Êµ¼ÊÉÏ£¬Äú¿ÉÒÔ°ÑË÷ÒýÀí½âΪһÖÖÌØÊâµÄĿ¼¡£Î¢ÈíµÄSQL SERVERÌṩÁËÁ½ÖÖË÷Òý£º¾Û¼¯Ë÷Òý£¨clustered index£¬Ò²³Æ¾ÛÀàË÷Òý¡¢´Ø¼¯Ë÷Òý£©ºÍ·Ç¾Û¼¯Ë÷Òý£¨nonclustered index£¬Ò²³Æ·Ç¾ÛÀàË÷Òý¡¢·Ç´Ø¼¯Ë÷Òý£©¡£ÏÂÃ棬ÎÒÃǾÙÀýÀ´ËµÃ÷һϾۼ¯Ë÷ÒýºÍ·Ç¾Û¼¯Ë÷ÒýµÄÇø±ð£º
¡¡¡¡Æäʵ£¬ÎÒÃǵĺºÓï×ÖµäµÄÕýÎı¾Éí¾ÍÊÇÒ»¸ö¾Û¼¯Ë÷Òý¡£±ÈÈ磬ÎÒÃÇÒª²é“°²”×Ö£¬¾Í»áºÜ×ÔÈ»µØ·­¿ª×ÖµäµÄÇ°¼¸Ò³£¬ÒòΪ“°²”µÄÆ´ÒôÊÇ“an”£¬¶ø°´ÕÕÆ´ÒôÅÅÐòºº×ÖµÄ×ÖµäÊÇÒÔÓ¢ÎÄ×Öĸ“a”¿ªÍ·²¢ÒÔ“z”½áβµÄ£¬ÄÇô“°²”×Ö¾Í×ÔÈ»µØÅÅÔÚ×ÖµäµÄÇ°²¿¡£Èç¹ûÄú·­ÍêÁËËùÓÐÒÔ“a”¿ªÍ·µÄ²¿·ÖÈÔÈ»ÕÒ²»µ½Õâ¸ö×Ö£¬ÄÇô¾Í˵Ã÷ÄúµÄ×ÖµäÖÐûÓÐÕâ¸ö×Ö£»Í¬ÑùµÄ£¬Èç¹û²é“ÕÅ”×Ö£¬ÄÇÄúÒ²»á½«ÄúµÄ×ֵ䷭µ½×îºó²¿·Ö£¬ÒòΪ“ÕÅ”µÄÆ´ÒôÊÇ“zhang”¡£Ò²¾ÍÊÇ˵£¬×ÖµäµÄÕýÎIJ¿·Ö±¾Éí¾ÍÊÇÒ»¸öĿ¼£¬Äú²»ÐèÒªÔÙÈ¥²éÆäËûĿ¼À´ÕÒµ½ÄúÐèÒªÕÒµÄÄÚÈÝ¡£ÎÒÃÇ°ÑÕâÖÖÕýÎÄÄÚÈݱ¾Éí¾ÍÊÇÒ»ÖÖ°´ÕÕÒ»¶¨¹æÔòÅÅÁеÄĿ¼³ÆΪ“¾Û¼¯Ë÷Òý”¡£
¡¡¡¡Èç¹ûÄúÈÏʶij¸ö×Ö£¬Äú¿É ......

SQL Server Ë÷Òý½á¹¹¼°ÆäʹÓ㨶þ£©

SQL Server Ë÷Òý½á¹¹¼°ÆäʹÓ㨶þ£©
×÷Õߣºfreedk
Ò»¡¢ÉîÈëdz³öÀí½âË÷Òý½á¹¹
¸ÄÉÆSQLÓï¾ä
¡¡¡¡ºÜ¶àÈ˲»ÖªµÀSQLÓï¾äÔÚSQL SERVERÖÐÊÇÈçºÎÖ´Ðеģ¬ËûÃǵ£ÐÄ×Ô¼ºËùдµÄSQLÓï¾ä»á±»SQL SERVERÎó½â¡£±ÈÈ磺
select * from table1 where name=''zhangsan'' and tID > 10000
ºÍÖ´ÐÐ:
select * from table1 where tID > 10000 and name=''zhangsan''
¡¡¡¡Ò»Ð©È˲»ÖªµÀÒÔÉÏÁ½ÌõÓï¾äµÄÖ´ÐÐЧÂÊÊÇ·ñÒ»Ñù£¬ÒòΪÈç¹û¼òµ¥µÄ´ÓÓï¾äÏȺóÉÏ¿´£¬ÕâÁ½¸öÓï¾äµÄÈ·ÊDz»Ò»Ñù£¬Èç¹ûtIDÊÇÒ»¸ö¾ÛºÏË÷Òý£¬ÄÇôºóÒ»¾ä½ö½ö´Ó±íµÄ10000ÌõÒÔºóµÄ¼Ç¼ÖвéÕÒ¾ÍÐÐÁË£»¶øÇ°Ò»¾äÔòÒªÏÈ´ÓÈ«±íÖвéÕÒ¿´Óм¸¸öname=''zhangsan''µÄ£¬¶øºóÔÙ¸ù¾ÝÏÞÖÆÌõ¼þÌõ¼þtID>10000À´Ìá³ö²éѯ½á¹û¡£
¡¡¡¡ÊÂʵÉÏ£¬ÕâÑùµÄµ£ÐÄÊDz»±ØÒªµÄ¡£SQL SERVERÖÐÓÐÒ»¸ö“²éѯ·ÖÎöÓÅ»¯Æ÷”£¬Ëü¿ÉÒÔ¼ÆËã³öwhere×Ó¾äÖеÄËÑË÷Ìõ¼þ²¢È·¶¨ÄĸöË÷ÒýÄÜËõС±íɨÃèµÄËÑË÷¿Õ¼ä£¬Ò²¾ÍÊÇ˵£¬ËüÄÜʵÏÖ×Ô¶¯ÓÅ»¯¡£
¡¡¡¡ËäÈ»²éѯÓÅ»¯Æ÷¿ÉÒÔ¸ù¾Ýwhere×Ó¾ä×Ô¶¯µÄ½øÐвéѯÓÅ»¯£¬µ«´ó¼ÒÈÔÈ»ÓбØÒªÁ˽âһϓ²éѯÓÅ»¯Æ÷”µÄ¹¤×÷Ô­Àí£¬Èç·ÇÕâÑù£¬ÓÐʱ²éѯÓÅ»¯Æ÷¾Í»á²»°´ÕÕÄúµÄ±¾Òâ½øÐпìËÙ²éѯ¡£
¡¡¡¡ÔÚ²éѯ·ÖÎö½×¶Î£¬²éѯÓÅ»¯Æ÷ ......

SQL Server Ë÷Òý½á¹¹¼°ÆäʹÓã¨Èý£©

SQL Server Ë÷Òý½á¹¹¼°ÆäʹÓã¨Èý£©
×÷Õߣºfreedk
Ò»¡¢ÉîÈëdz³öÀí½âË÷Òý½á¹¹
¶þ¡¢¸ÄÉÆSQLÓï¾ä
ʵÏÖСÊý¾ÝÁ¿ºÍº£Á¿Êý¾ÝµÄͨÓ÷ÖÒ³ÏÔʾ´æ´¢¹ý³Ì
¡¡¡¡½¨Á¢Ò»¸ö Web Ó¦Ó㬷ÖÒ³ä¯ÀÀ¹¦Äܱز»¿ÉÉÙ¡£Õâ¸öÎÊÌâÊÇÊý¾Ý¿â´¦ÀíÖÐÊ®·Ö³£¼ûµÄÎÊÌâ¡£¾­µäµÄÊý¾Ý·ÖÒ³·½·¨ÊÇ:ADO ¼Í¼¼¯·ÖÒ³·¨£¬Ò²¾ÍÊÇÀûÓÃADO×Ô´øµÄ·ÖÒ³¹¦ÄÜ£¨ÀûÓÃÓα꣩À´ÊµÏÖ·ÖÒ³¡£µ«ÕâÖÖ·ÖÒ³·½·¨½öÊÊÓÃÓÚ½ÏСÊý¾ÝÁ¿µÄÇéÐΣ¬ÒòΪÓα걾ÉíÓÐȱµã£ºÓαêÊÇ´æ·ÅÔÚÄÚ´æÖУ¬ºÜ·ÑÄÚ´æ¡£ÓαêÒ»½¨Á¢£¬¾Í½«Ïà¹ØµÄ¼Ç¼Ëøס£¬Ö±µ½È¡ÏûÓαꡣÓαêÌṩÁ˶ÔÌض¨¼¯ºÏÖÐÖðÐÐɨÃèµÄÊֶΣ¬Ò»°ãʹÓÃÓαêÀ´ÖðÐбéÀúÊý¾Ý£¬¸ù¾ÝÈ¡³öÊý¾ÝÌõ¼þµÄ²»Í¬½øÐв»Í¬µÄ²Ù×÷¡£¶ø¶ÔÓÚ¶à±íºÍ´ó±íÖж¨ÒåµÄÓα꣨´óµÄÊý¾Ý¼¯ºÏ£©Ñ­»·ºÜÈÝÒ×ʹ³ÌÐò½øÈëÒ»¸öÂþ³¤µÄµÈ´ýÉõÖÁËÀ»ú¡£
¡¡¡¡¸üÖØÒªµÄÊÇ£¬¶ÔÓڷdz£´óµÄÊý¾ÝÄ£ÐͶøÑÔ£¬·ÖÒ³¼ìË÷ʱ£¬Èç¹û°´ÕÕ´«Í³µÄÿ´Î¶¼¼ÓÔØÕû¸öÊý¾ÝÔ´µÄ·½·¨ÊǷdz£ÀË·Ñ×ÊÔ´µÄ¡£ÏÖÔÚÁ÷ÐеķÖÒ³·½·¨Ò»°ãÊǼìË÷Ò³Ãæ´óСµÄ¿éÇøµÄÊý¾Ý£¬¶ø·Ç¼ìË÷ËùÓеÄÊý¾Ý£¬È»ºóµ¥²½Ö´Ðе±Ç°ÐС£
¡¡¡¡×îÔç½ÏºÃµØʵÏÖÕâÖÖ¸ù¾ÝÒ³Ãæ´óСºÍÒ³ÂëÀ´ÌáÈ¡Êý¾ÝµÄ·½·¨´ó¸Å¾ÍÊÇ“¶íÂÞ˹´æ´¢¹ý³Ì”¡£Õâ¸ö´æ´¢¹ý³ÌÓÃÁËÓα꣬ÓÉÓÚÓαêµÄ¾ÖÏÞÐÔ£¬ËùÒÔÕâ¸ö·½·¨²¢Ã»Óеõ ......

SQL Server Ë÷Òý½á¹¹¼°ÆäʹÓã¨ËÄ£©

SQL Server Ë÷Òý½á¹¹¼°ÆäʹÓã¨ËÄ£©
×÷Õߣºfreedk
Ò»¡¢ÉîÈëdz³öÀí½âË÷Òý½á¹¹
¶þ¡¢¸ÄÉÆSQLÓï¾ä
Èý¡¢ÊµÏÖСÊý¾ÝÁ¿ºÍº£Á¿Êý¾ÝµÄͨÓ÷ÖÒ³ÏÔʾ´æ´¢¹ý³Ì
¾Û¼¯Ë÷ÒýµÄÖØÒªÐÔºÍÈçºÎÑ¡Ôñ¾Û¼¯Ë÷Òý
¡¡¡¡ÔÚÉÏÒ»½ÚµÄ±êÌâÖУ¬±ÊÕßдµÄÊÇ£ºÊµÏÖСÊý¾ÝÁ¿ºÍº£Á¿Êý¾ÝµÄͨÓ÷ÖÒ³ÏÔʾ´æ´¢¹ý³Ì¡£ÕâÊÇÒòΪÔÚ½«±¾´æ´¢¹ý³ÌÓ¦ÓÃÓÚ“°ì¹«×Ô¶¯»¯”ϵͳµÄʵ¼ùÖÐʱ£¬±ÊÕß·¢ÏÖÕâµÚÈýÖÖ´æ´¢¹ý³ÌÔÚСÊý¾ÝÁ¿µÄÇé¿öÏ£¬ÓÐÈçÏÂÏÖÏó£º
1¡¢·ÖÒ³ËÙ¶ÈÒ»°ãά³ÖÔÚ1ÃëºÍ3ÃëÖ®¼ä¡£
2¡¢ÔÚ²éѯ×îºóһҳʱ£¬ËÙ¶ÈÒ»°ãΪ5ÃëÖÁ8Ã룬ÄÄÅ·ÖÒ³×ÜÊýÖ»ÓÐ3Ò³»ò30ÍòÒ³¡£
¡¡¡¡ËäÈ»ÔÚ³¬´óÈÝÁ¿Çé¿öÏ£¬Õâ¸ö·ÖÒ³µÄʵÏÖ¹ý³ÌÊǺܿìµÄ£¬µ«ÔÚ·ÖÇ°¼¸Ò³Ê±£¬Õâ¸ö1£­3ÃëµÄËٶȱÈÆðµÚÒ»ÖÖÉõÖÁûÓо­¹ýÓÅ»¯µÄ·ÖÒ³·½·¨ËٶȻ¹ÒªÂý£¬½èÓû§µÄ»°Ëµ¾ÍÊÇ“»¹Ã»ÓÐACCESSÊý¾Ý¿âËٶȿ씣¬Õâ¸öÈÏʶ×ãÒÔµ¼ÖÂÓû§·ÅÆúʹÓÃÄú¿ª·¢µÄϵͳ¡£
¡¡¡¡±ÊÕ߾ʹ˷ÖÎöÁËһϣ¬Ô­À´²úÉúÕâÖÖÏÖÏóµÄÖ¢½áÊÇÈç´ËµÄ¼òµ¥£¬µ«ÓÖÈç´ËµÄÖØÒª£ºÅÅÐòµÄ×ֶβ»ÊǾۼ¯Ë÷Òý£¡
¡¡¡¡±¾ÆªÎÄÕµÄÌâÄ¿ÊÇ£º“²éѯÓÅ»¯¼°·ÖÒ³Ëã·¨·½°¸”¡£±ÊÕßÖ»ËùÒÔ°Ñ“²éѯÓÅ»¯”ºÍ“·ÖÒ³Ëã·¨”ÕâÁ½¸öÁªÏµ²»ÊǺܴóµÄÂÛÌâ·ÅÔÚÒ»Æ𣬾ÍÊÇÒòΪ¶þÕ߶¼ÐèÒªÒ ......

SQLµÝ¹é²éѯ²¿ÃÅ

create function [dbo].[DeptTree](@initDeptCode  varchar(10))/*¶¨Ò庯Êýc_tree£¬ÊäÈë²ÎÊýΪ³õʼ½ÚµãDeptCode*/
returns @t table(DeptCode varchar(10),UpDeptCode  varchar(10),lev int)/*¶¨Òå±ítÓÃÀ´´æ·ÅÈ¡³öµÄÊý¾Ý*/
begin
  declare @i int/*±êÖ¾µÝ¹é¼¶±ð*/
  set @i=1
  insert @t select DeptCode,UpDeptCode,@i from vi_dept where DeptCode=@initDeptCode
  while @@rowcount<>0
  begin
  set @i=@i+1
  insert @t select a.DeptCode,a.UpDeptCode,@i from vi_dept as a,@t as b
 where b.DeptCode=a.UpDeptCode and b.lev=@i-1
  end
return
end
 select * from dbo.DeptTree('0000')
......
×ܼǼÊý:4346; ×ÜÒ³Êý:725; ÿҳ6 Ìõ; Ê×Ò³ ÉÏÒ»Ò³ [716] [717] [718] [719] [720] [721] [722] 723 [724] [725]  ÏÂÒ»Ò³ βҳ
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ