代码拉取完成,页面将自动刷新
同步操作将从 济南驰骋公司/CCFlow 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
/** 以下代码由孙战平 2013.07.19 */
--GO--
Create FUNCTION [dbo].[f_FixNumLen]
(
@str nvarchar(200),
@len int
)
RETURNS nvarchar(200)
AS
BEGIN
if(@len>len(@str))
set @str = replicate('0',@len-len(@str))+@str;
return @str;
END
--GO--
Create PROCEDURE [dbo].[sp_get_tree_table]
(@table_name nvarchar(200), @id nvarchar(50), @name nvarchar(50), @parent_id nvarchar(50) , @orderBy nvarchar(50), @startParentId nvarchar(20),@is_top bit, @FixLenFlag int)
AS
declare @v_affect int
declare @v_level int
declare @sql nvarchar(500)
begin
create table #temp (id nvarchar(20),name nvarchar(50),parent_id nvarchar(20),level int,treespace nvarchar(500),orderid int);
declare @strTable varchar(200);
set @table_name=LTRIM(@table_name);
if(charindex('from ',lower(@table_name))=1)
set @strTable='select * '+@table_name;
else
Begin
if(charindex('select ',lower(@table_name))<>1 and charindex(' where ',lower(@table_name))>1)
set @strTable='select * from '+@table_name;
else
set @strTable=@table_name;
End
if(charindex('select ',lower(@strTable))=1)
set @strTable='('+@strTable+')'
if(charindex('(select ',lower(@strTable))=1)
set @sql='insert into #temp(id,name,parent_id,orderid) select '+@id+','+@name+','+@parent_id +','+@orderBy+' from ' + @strTable +' as A';
else
set @sql='insert into #temp(id,name,parent_id,orderid) select '+@id+','+@name+','+@parent_id +','+@orderBy+' from ' + @strTable +'';
exec sp_executesql @sql;
set @v_level=1;
set @v_affect=1;
while(@v_affect>0)
Begin
if @v_level=1
if @startParentId is null
update #temp
set level=@v_level,treespace=dbo.f_FixNumLen(Cast(orderid as varchar),@FixLenFlag) +'-'+dbo.f_FixNumLen(Cast(id as varchar),@FixLenFlag)
where parent_id is null;
else
update #temp
set level=@v_level,treespace=dbo.f_FixNumLen(Cast(orderid as varchar),@FixLenFlag) +'-'+dbo.f_FixNumLen(Cast(id as varchar),@FixLenFlag)
where parent_id = CAST(@startParentId as int);
else
update #temp
set level=@v_level,treespace=(select A.treespace from #temp A where A.id=#temp.parent_id)+'-'+dbo.f_FixNumLen(Cast(orderid as varchar),@FixLenFlag) +'-'+dbo.f_FixNumLen(Cast(id as varchar),@FixLenFlag)
where parent_id in (select id from #temp A where A.level=@v_level-1);
set @v_affect=@@ROWCOUNT;
set @v_level=@v_level+1;
End
delete from #temp where level is null;
if @is_top=1
select id,(case when level>1 then REPLICATE('│',level-2) else '' end)+(case when level>1 then '├' else '' end) + name as name
from #temp order by treespace;
else
select id,REPLICATE('│',level-1) + '├' + name as name
from #temp order by treespace;
end
--GO--
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。