我创建了两个临时表
#FileIndex,#tC
create table #FileIndex( 
number varchar(30),
FileIndexSequence numeric
)
create table #tC(
number varchar(30)
)
然后插入第二表一条记录
insert into #tC values (‘0000000001')
在插入第一个表,符合第二表的记录。
insert into #FileIndex select #tC.number, Sequence from #tc inner join FileIndex DOCFix on #tc.number=DOCFix.number
这里FileIndex 是已经存在于数据库中有数据的表,要求number的值和Sequence 。
然后添加表一字段Alter table #FileIndex add FileIndexSection varchar(20)
后查询
select * from #FileIndex 
SQL QA 报错:服务器: 消息 213,级别 16,状态 4,行 11
Insert Error: Column name or number of supplied values does not match table definition.
但是在Alter table语句后加上GO问题就没有出现了。
但现在这语句要写在存储过程中,并前面有上个存储过程传过来的参数,如果在存储过程中写了GO
就会
务器: 消息 137,级别 15,状态 2,行 4
Must declare the variable '@Columns'.
服务器: 消息 137,级别 15,状态 1,行 6
Must declare the variable '@Columns'.
请各位高手看下。

解决方案 »

  1.   

    我在这附上全段代码的整体:
    create table #FileIndex( 
    number varchar(30),
    FileIndexSequence numeric
    )
    create table #tC(
    number varchar(30)
    )--select #tC.number, Sequence
    --from #tc inner join FileIndex DOCFix on #tc.number=DOCFix.number
    insert into #tC values ('0000000001')select * from #tC
    select * from #FileIndexinsert into #FileIndex select #tC.number, Sequence from #tc inner join FileIndex DOCFix on #tc.number=DOCFix.number
    select * from #FileIndexalter table #FileIndex add fileIndex varchar(255) null
    --GO
    select * from #tEDMSNo_FileIndex
      

  2.   

    是可以加,但是在存储过程中加上的话,会导致临时保存的被清空。
    比如
    declare @aa varchar(10)
    select @aa='aa'
    下面在加上
    原先的语句
    然后在GO了以后查询
    select @aa

    服务器: 消息 137,级别 15,状态 2,行 1
    Must declare the variable '@aa'.
      

  3.   

    必须在动态SQL语句中处理这些。
      

  4.   

    在存储中只能使用动态SQL语句来执行GO
    否则,GO后面的语句将不会被创建。
    Go之前,和GO之间的语句被当作来一个批来处理。遇到GO,分析器将执行Go之前的语句之后再分析后面的语句。