create procedure test
@id  int,
@name  varchar(10)
as
begin
    insert into  t2
    select a.*,@name from  t1 where id=@id
end

解决方案 »

  1.   

    create proc test
    @id int,
    @name varchar(50)
    as
    --注意好字段对应
    insert tb2(col列表) select tb1字段列表,@name  from tb1 where id=@id
      

  2.   

    create proc Test (@id int,@name varchar(20))
    as 
    begin
       SELECT * INTO #T from 表1 Where id = @id 
        
       begin tran 
         insert into 表2(id,name,.........)
         SELECT @id,@name,.......
         FROM #T 
         if (@@error <> 0)
            rollback tran    commit tran 
    end
      

  3.   

    create proc Test (@id int,@name varchar(20))
    as 
    begin
    if  (select count(*) from tb1 where id=@id)=0 print begin '无此记录' ;rollback; end\
    else 
    insert tb2(你要插入的字段)--注意你插入字段的顺序
    select @name,你要选取的字段
    from tb1
    where id=@idend
      

  4.   

    修改
    create proc Test (@id int,@name varchar(20))
    as 
    begin
    if  (select count(*) from tb1 where id=@id)=0
     begin
     print '无此记录' ;rollback; 
    end
    else 
    insert tb2(你要插入的字段)--注意你插入字段的顺序
    select @name,你要选取的字段
    from tb1
    where id=@idend
      

  5.   

    create proc ins_t2
      @id varchar(10)
    as
    select * into #aa from t1 where ID=@id     --将满足条件的记录存到临时表#aa
    insert t1(列1-列N) SELECT 列1-列N from #aa  --插入数据(数据来自临时表)
    go