EXEC ('alter table [a1] ADD coef nvarchar(100)')------字段的类型

解决方案 »

  1.   

    给错问题了,EXEC ('alter table [a1] ADD coef float null  '),这个地方是这么写的,不好意思
      

  2.   

    EXEC ('alter table [a1] ADD coef float null  ')
    后面加 go
      

  3.   

    不行啊,加了GO后,报错
    服务器: 消息 170,级别 15,状态 1,行 138
     ')' 附近有语法错误。
    服务器: 消息 156,级别 15,状态 1,行 1
    在关键字 'end' 附近有语法错误。
    服务器: 消息 156,级别 15,状态 1,行 14
    在关键字 'end' 附近有语法错误。
      

  4.   

    begin tran
    select * into #tmp1 from [a1] with (TABLOCKX)
    select * into #tmp2 from a2 with (TABLOCKX)       
    if not exists (select * from a2 where TbName = 'a1')
    begin
    if exists (select b.* from syscolumns as a, sysobjects as b
    where a.id=b.id and b.name='a1' and (a.name = 'Coef' ))
    begin
           EXEC ('update [a1] set coef = null ')
    end 
    else
    begin
           EXEC ('alter table [a1] ADD coef float null  ')
    end 
    exec('
    update [a1]     --老是说列名‘coef’无效,报错
    set coef = b.coef 
    FROM [a1] as a,#tmp3 as b
    where a.familycode = b.familycode')
    end
    commit tran