是否可以在不定义模式的情况下插入表变量?是否可以在不定义模式的情况下插入表变量?
我需要做的这个像
Declare @tab1 as table
Insert into @tab1 select * from table2
Select * from @tab1
我尝试此查询,但得到的错误。
请帮忙。
是否可以在不定义模式的情况下插入表变量?是否可以在不定义模式的情况下插入表变量?
我需要做的这个像
Declare @tab1 as table
Insert into @tab1 select * from table2
Select * from @tab1
我尝试此查询,但得到的错误。
请帮忙。
错误在第一行
Msg 102,Level 15,State 1,Line 1 'table'附近的语法不正确。
代替申报@ TAB1如表尝试
申报@ TAB1如表(COL1 VARCHAR(100)),即全表模式
例如
申报@ TAB1如表(COL1 VARCHAR(100))
插入@ TAB1从@从tblInformation
选择*选择[用户名] TAB1
输出:
个COL1
XYZ
ABC
错误与该行:
申报@ TAB1如表
附近有语法错误 '表'。
,但你也取得了与插入一个错误应该是:
select * into tab1
from table2
据我知道你需要使用表可变因素时,申报方案,如果使用临时表你不”牛逼所以这会工作
select * into #tab1
from table2
见msdn
这将工作:
declare @tab table (BillID int)
insert into @tab
select top 10 BillID from tblBill
select * from @tab
这是行不通的:
select top 10 BillID into @tab from tblBill
select * from @tab
如果你想定义的飞行表VAR的模式,你可以使用这样的事情:
declare @str varchar(1000)
set @str = 'declare @tab table (BillID int) ' +
'insert into @tab ' + 'select top 10 BillID from tblBill ' + 'select * from @tab '
exec(@str)
而且,在Pinal Dave的网站上查找(sp_executesql)以获得一些好的建议
我喜欢你的个人档案相片:) – leppie 2009-10-09 10:06:06