首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

表变量有关问题

2012-01-21 
表变量问题--请看代码declare@g1table(patint)----创建一个测试表insertinto@g1(pat)select0unionallselec

表变量问题
--请看代码
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)
[解决办法]
啊喔...偶看錯了:)

热点排行