set @vi_levelpath = 1
--得到所有物件,不包括系統物件
insert into @vt_objdeppath(levelpath,oname,type)
select @vi_levelpath,o.name ,o.type
from sysobjects o
where xtype not in ( 's ', 'x ')
--得到依賴物件的名稱
insert into @vt_temp1(oname)
select distinct object_name(sysdepends.depid)
from sysdepends,@vt_objdeppath p
where sysdepends.id <> sysdepends.depid
and p.oname = object_name(sysdepends.id)
--迴圈處理:由物件而得到其依賴物件
while (select count(*) from @vt_temp1) > 0
begin
set @vi_levelpath = @vi_levelpath + 1
update @vt_objdeppath
set levelpath = @vi_levelpath
where oname in (select oname from @vt_temp1)
and levelpath = @vi_levelpath - 1
delete from @vt_temp2
insert into @vt_temp2
select * from @vt_temp1
delete from @vt_temp1
insert into @vt_temp1(oname)
select distinct object_name(sysdepends.depid)
from sysdepends,@vt_temp2 t2
where t2.oname = object_name(sysdepends.id)
and sysdepends.id <> sysdepends.depid
end
select @vi_levelpath = max(levelpath) from @vt_objdeppath
--修改沒有依賴物件的物件級別為最大
update @vt_objdeppath
set levelpath = @vi_levelpath + 1
where oname not in (select distinct object_name(sysdepends.id) from sysdepends)
and levelpath = 1
insert into @v_result
select * from @vt_objdeppath order by levelpath desc
return
end
go --呼叫方法
select * from dbo.udf_genlevelpath() where type='u'
go **:
按照依賴關係排序
import copy import utils.functool utils.functool.settimeout timeout 15 def dependsonsort testfunnames,dependrelation 有個問題就是如果出現a依賴b,而b又依賴a就會出現問題 param...
多表查詢後按照拼音排序
select p.fprovinceid,p.fprovince from t bas province p where exists select from t bas businessdept b inner join t bas city c on b.fnewcity c.fid where...
mysql 查詢按照中文進行排序
在mysql中我們使用order by來實現查詢排序,如 select from member order by id asc 查詢使用者表並按照id正序排序 select from member order by id desc 查詢使用者表並按照id倒序排序但是我們如果想要排序的字段為中文時,這...