select 
  'JHB-22-090309-01' as no,
  id=identity(int 1,1)
into #
from 作业 
where 选择='Y' insert into 计划(单号,ID) select * from #drop table #

解决方案 »

  1.   

    --search
    select m.* , id = (select count(1) from 
    (
      select 'JHB-22-090309-01' 单号 from 作业 where 选择='Y' 
    ) n where 单号 < m.单号
    ) + 1 from
    (
      select 'JHB-22-090309-01' 单号 from 作业 where 选择='Y' 
    ) m--insert
    insert into 计划(单号,ID) 
    select m.* , id = (select count(1) from 
    (
      select 'JHB-22-090309-01' 单号 from 作业 where 选择='Y' 
    ) n where 单号 < m.单号
    ) + 1 from
    (
      select 'JHB-22-090309-01' 单号 from 作业 where 选择='Y' 
    ) m