create proc test
as 
select identity(int,1,1) FID,* into #A from 表a order by id
select identity(int,1,1) FID,* into #B from 表b order by id
insert temp
select 'A-'+cast(fid as varchar) ,m,n from #A where id=1
union all
select 'B-'+cast(fid as varchar) ,x,y from #B where id=1
select * from temp
drop table #a
drop table #b

解决方案 »

  1.   

    --呵呵,改了下楼上的create proc test
    as 
    select identity(int,1,1) FID,* into #A from 表a where id=1
    select identity(int,1,1) FID,* into #B from 表b where id=1insert temp
    select 'A-'+cast(fid as varchar) ,m,n from #A
    union all
    select 'B-'+cast(fid as varchar) ,x,y from #Bselect * from tempdrop table #adrop table #b
      

  2.   

    CREATE PROC P_INSERT 
      AS
       SELECT IDENTITY(INT,1,1) IDD,* INTO #T_A FROM TableA 
       SELECT IDENTITY(INT,1,1) IDD,* INTO #T_B FROM TableB
      INSERT INTO TEMP SELECT 'A-'+CAST(IDD AS CHAR(1)),M,N FROM #T_A WHERE ID<3
      INSERT ITNO TEMP SELECT 'B-'+CAST(IDD AS CHAR(1)),M,N FROM #T_A WHERE ID<3
      SELECT * FROM #T_A
      DROP TABLE #T_A
      DROP TABLE #T_BGO