日期:2014-05-19  浏览次数:20441 次

表变量问题
--请看代码
declare   @g1   table(pat   int)
  ----   创建一个测试表
insert   into   @g1(pat)
select   0   union   all  
select   0   union   all  
select   0   union   all  
select   0   union   all  
select   1   union   all  
select   2   union   all  
select   3   union   all  
select   4   union   all  
select   5   union   all  
select   6   union   all  
select   7   union   all  
select   8   union   all  
select   9  

declare   @i   smallint
set   @i=5
while   @i> 0
begin
insert   into   @g1           《《可能是这里出错
select   pat   from   @g1
set   @i=@i-1
end
select   *   from   @g1
----
请问那里出错?

------解决方案--------------------
没问题的,我的执行成功。
------解决方案--------------------
有表變量,使用動態SQL

select * from @g1 ==> exec( 'select * from '+@g1)
------解决方案--------------------
啊喔...偶看錯了:)