select a.name,a.address into table1 from a inner join b on a.id=b.id order by b.type a.name

解决方案 »

  1.   

    insert into 新表
    select a.姓名, a.住址
    from 表一 a inner join 表二 b on a.编号 = b.编号
    where b.分类 = ...
      

  2.   

    1.新表不存在
    select a.客户姓名,a.住址 into 新表  
    from 表1 a join 表2 b on a.编号 = b.编号 and b.分类 = ....
    2.新表已存在
    insert 新表
    select a.客户姓名,a.住址 
    from 表1 a join 表2 b on a.编号 = b.编号 and b.分类 = ....
    ----
    这样????
      

  3.   

    insert c(姓名,住址)
    select a.姓名,a.住址 from a,b and a.编号=b.编号 and b.分类=@变量
      

  4.   

    select 表1.客户姓名,表1.住址 into #newtable from 表1 a join 表2 b on a.编号 = b.编号 and b.分类=(你自己定义)
      

  5.   

    --根据表2的分类是什么意思?--插入到已经创建好的表中insert into 表
    select b.分类,a.姓名,a.住址
    from 表1 a join 表2 b on a.客户编号=b.客户编号
    --表不存在时生成表
    select b.分类,a.姓名,a.住址
    into 新表
    from 表1 a join 表2 b on a.客户编号=b.客户编号
      

  6.   

    --如果是每个分类生成一张新表,就用:declare @分类 varchar(20)
    declare tb cursor for select 分类 from 表2
    open tb
    fetch next from tb into @分类
    while @@fetch_status=0
    begin
    exec('select a.姓名,a.住址 into ['+@分类+'] from 表1 a join 表2 b on a.客户编号=b.客户编号 where b.分类='''+@分类+'''')
    fetch next from tb into @分类
    end
    close tb
    deallocate tb
      

  7.   

    select a.客户姓名,a.住址 into 新表  
    from 表1 a join 表2 b on a.编号 = b.编号 and b.分类 = ....
      

  8.   

    参考:
    /*
    以下是将t1的数据导入到t2中的方法:
    */--1、如果表t2不存在:
    --导入全部字段
    select * into t2 from t1
    --导入部分字段
    select col1,col2,col3... into t2 from t1
    --导入全部并且增加自动编号(t1中没有)字段
    select identity(int,1,1) id,col1,col2,col3... into t2 from t1
    --导入全部并且增加新的自动编号(t1中原来有自动编号id)字段
    select identity(int,1,1) id1,cast(id as int) id2,col1,col2,col3... into t2 from t1--2、如果表t2存在:
    --导入全部(注意字段的类型一样)
    insert t2 select * from t1
    --导入部分字段
    insert t2(col1,col2,col3..) select col1,col2,col3... from t1
    --表t1(id,col1,col2...),表t2(id,col1,col2...)存在,两个表中都有自动增量id。
    --(1):不导入自动增量
    insert t2(col1,col2...) select col1,col2... from t1
    --(2):导入自动增量
    set identity_insert t2 on
    insert t2(id,col1,col2...) select id,col1,col2... from t1
    set identity_insert t2 off