表A:
注册编号,姓名
表B:
注册编号,姓名,年龄,学校insert into B(注册编号,姓名,年龄,学校) values (select top 1 注册编号 from A order by 注册编号 desc,@姓名,@年龄,@学校)---------------
select报错。

解决方案 »

  1.   

    declare @姓名 varchar(50),@年龄 varchar(50),@学校 varchar(50),@注册编号 varchar(50)
    set @注册编号=(select top 1 注册编号 from A order by 注册编号 desc)
    insert into B(注册编号,姓名,年龄,学校) 
    select @注册编号,@姓名,@年龄,@学校
    --或
    insert into B(注册编号,姓名,年龄,学校) 
    select (select top 1 注册编号 from A order by 注册编号 desc),@姓名,@年龄,@学校
      

  2.   


    insert into B(注册编号,姓名,年龄,学校)  select top 1 注册编号,@姓名,@年龄,@学校 
    from A 
    order by 注册编号 desc
      

  3.   

    insert into B(注册编号,姓名,年龄,学校) 
    select top 1 注册编号,@姓名,@年龄,@学校 from A order by 注册编号 desc
      

  4.   

    declare @t1 table (a char(3),b char(3))
    declare @t2 table (a char(3),b char(3),c char(3))
    insert into @t1 (a,b) select 'a1','b1'
    insert into @t1 (a,b) select 'a2','b2'
    insert into @t1 (a,b) select 'a3','b3'
    insert into @t2(a,b,c) select (select top 1 a from @t1 order by a),'bb','cc'
    select * from @t2values 错误
      

  5.   

    insert into (c1,c2,c3) values(@c1,@c2,@c3)和insert into (c1,c2,c3) select(@c1,@c2,@c3)
    请教语法上有何不同啊?
      

  6.   

    最后还是用values 搞定,select还是有问题。谢谢大家了,结帖