CODE 包含上千个,要生成上千个表。

解决方案 »

  1.   

    declare @t table (CODE varchar(10))
    insert @t 
    select 'AAA' union all
    select 'AAA' union all
    select 'AAA' union all
    select 'BBB' union all
    select 'BBB' union all
    select 'BBB' union all
    select 'CCC' union all
    select 'CCC' union all
    select 'CCC' select 'select * into '+code+' from @t where CODE='+CODE as 生成语句 from @T group by code/*
    生成语句
    ------------------------------------------------------
    select * into AAA from @t where CODE=AAA
    select * into BBB from @t where CODE=BBB
    select * into CCC from @t where CODE=CCC
    */
      

  2.   

    declare @t table (CODE varchar(10))
    insert @t 
    select 'AAA' union all
    select 'AAA' union all
    select 'AAA' union all
    select 'BBB' union all
    select 'BBB' union all
    select 'BBB' union all
    select 'CCC' union all
    select 'CCC' union all
    select 'CCC' select 'select * into '+code+' from @t where CODE='+CODE as 生成语句 from @T group by code/*
    生成语句
    ------------------------------------------------------
    select * into AAA from @t where CODE=AAA
    select * into BBB from @t where CODE=BBB
    select * into CCC from @t where CODE=CCC
    */
      

  3.   

    现在是使用一个程序来处理,如果不能用一条SQL语句解决的问题,就复杂很多。
      

  4.   

    MASTER.DBO.XP_EXECRESULTSET 'SELECT DISTINCT ''SELECT  * INTO STOCK_''+code+'' FROM STOCK WHERE CODE=''''''+CODE+'''''''' FROM STOCK s 
    ',N'库名'