我有如下一表结构:
字段1     字段2
A         table1
B         table1
C         table2
...        ....
如果我数据库对应的table1 table2...中不包含上表对应的字段1里的记录(A B C...)就将table1,table2...新增A B C...字段
意思是table1  字段(D,E,)变为(A B D E)
   talbe2  字段(H)  变为(C H)

解决方案 »

  1.   

    乱了呵呵
    不过你问的问题用left outer join or inner join肯定能完成
    最好写成存储过程
    CREATE PROCEDURE Code
    @strUCode char(8)
    AS SELECT Distinct Seal.SState as 名称1,
    Seal.Code AS 名称2,
    Seal.SName AS 名称3,
    FROM Seal INNER JOIN GDUser ON SealData.Code=User.Code
     LEFT JOIN Company ON Seal.SNO=Company.SNO
    where 
     
    User.strUCode=@strUCode
     
    GO
      

  2.   

    看了半天,终于明白你的意思.但不会写....建议到sql server版去问.......
      

  3.   

    一楼:table1,table2是数据表啊.对于它们得用atler table ..........
      

  4.   

    是alter table 楼主:你得描述
    table1,table2什么时候作为记录值,
    什么时候作为数据表才好理解点.因为table1作为记录值时,对应的相应记录数为不定值,我觉得要写个动态语句,但偏不熟悉,就高手指点...
      

  5.   

    hehe, 是動態修正数据表結構問題。数据库是什麼的?SQL Server?
      

  6.   

    declare @column varchar(50)while not @column is null
    begin
    set @column = null
    select top 1 @column = field1 from t where not exists(select * From syscolumns where name=field2 and id=object_id(field1)
     
    exec ('ALTER TABLE table1 ADD COLUMN ' + @column + ' varchar(50)')
    end
    大致是这样,没有测试。