当前位置:编程学习 > C#/ASP.NET >>

关于SQL的一个问题,高手们,来吧,跪求,我是菜鸟,数据库不常用.........

关于SQL 复制表后,见图:

 


  

把template表中的template_name,file_code插入到 folder表中 

template_id      name                parentid       file_code

66                    ttttt                    0              

67                    4444                  66

68                    77777                67

 插入到 folder表中图为:

folder_id,       folder_name,               parent_id,             file_code

1200                tttt                              0

1201                4444                         1200

1202                 7777                        1201

 

储过程写到这里了

ALTER PROCEDURE [dbo].[sp_DocumentTemplateCopy] 
(
    @CompanyCode varchar(100),         -- 创建的文件夹跟目录
    @TemplateType varchar(100),        -- 输入要复制的模板类型
    @CreateUserName varchar(50),        -- 创建用户名
    @FiledValue int output
)
AS 
begin

    IF(ISNULL(@CompanyCode,'') <> '')
        begin

            declare @sql nvarchar(500);
            set @sql='set @num= (SELECT count(1) FROM [tbl_document_folder] WHERE folder_name ='''+ @CompanyCode +''' AND parent_id =0)';
            EXECUTE sp_executesql @sql ,N'@num INT output',@FiledValue OUTPUT
            if((@FiledValue=0) and ISNULL(@TemplateType,'') <> '')
            begin


                    create table #temp
                    (
                         template_id INT,
                         template_type nvarchar(100),
                         template_name nvarchar(100),
                         parent_id INT,
                         file_code nvarchar(100),
                         sort_id INT
                   );
 
                     insert into #temp    (template_id,template_type,template_name,parent_id,file_code,sort_id)
                    exec sp_Doc_DocTemplateTree @TemplateType;

   

           //现在临时表就为 上图中的template 表,上图中的template是经过存储过程处理后的表,然后新建临时表存储结果,然后把结果插入到folder表,如图那样,小弟sql时间不长,很多东西都不太用,求指教        

 
     

                    drop table #temp
            end
     end

end
--------------------编程问答-------------------- 没看到问题是什么
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,