Where is my way?

 

Delphi工作笔记-从表格中导入数据到数据库

今天要更新预算项目,由客户整理好编号 名称 级别 

由于要按树结构格式排列,所以写了一个游标去处理

先由 sqlserver2000 企业管理器将内容导入

declare @ID        uniqueidentifier
declare @Code UCode --varchar(50)
declare @TreeLevel int
Declare c cursor for
Select ID,Code,TreeLevel from 结果 ORDER BY Code
open c
fetch next from c into @ID, @Code, @TreeLevel
while @@fetch_status=0
begin

select NewID(), t.Code,@Code from 结果 t where @Code Like Code+'%' and TreeLevel=@TreeLevel-1
fetch next from c into @ID, @Code, @TreeLevel
end
close c
deallocate c




declare @ID uniqueidentifier
declare @Code UCode
declare @TreeLevel int
declare @PID UID
Declare c cursor for
Select ID,Code,TreeLevel from 结果 ORDER BY Code
open c
fetch next from c into @ID, @Code, @TreeLevel
while @@fetch_status=0
begin
select @PID=t.ID from 结果 t where @Code Like Code+'%' and TreeLevel=@TreeLevel-1
update 结果 set ParentID=@PID where Code=@Code
fetch next from c into @ID, @Code, @TreeLevel
end
close c
deallocate c



posted on 2011-09-22 22:53  ManLoveGirls  阅读(393)  评论(0编辑  收藏  举报

导航