insert into A(字段)
select content from #temp
where content like 'A%' and content not in (select 字段 from a)B,C的同理

解决方案 »

  1.   

    insert into A 
    from #temp as tt
    where substring(content,1,1)='A'
      and not exists (select 1 from #temp where A.content=tt.content)
      

  2.   


    declare @s varchar(8000)
    declare cursor1 scroll cursor for select content from #
    open cursor1fetch next from cursor1 into @swhile @@fetch_status = 0
       begin 
          if substring(@s , 1, 1) = 'A' 
              begin 
                  if exists(select 1 from tab_A where col1 = @s)
                     begin 
                         insert into tab_A
                         select @s
                     end 
              end 
          
          if substring(@s , 1, 1) = 'B' 
              begin 
                  if exists(select 1 from tab_B where col1 = @s)
                     begin 
                         insert into tab_B
                         select @s
                     end 
              end 
         
          if substring(@s , 1, 1) = 'C' 
              begin 
                  if exists(select 1 from tab_C where col1 = @s)
                     begin 
                         insert into tab_C
                         select @s
                     end 
              end 
     
         fetch next from cursor1 into @s    end 
    close cursor1
    deallocate cursor1