Sql 是否可以在不定义模式的情况下插入表变量?
是否可以在不定义模式的情况下插入表变量 我需要这样做Sql 是否可以在不定义模式的情况下插入表变量?,sql,sql-server-2005,Sql,Sql Server 2005,是否可以在不定义模式的情况下插入表变量 我需要这样做 Declare @tab1 as table Insert into @tab1 select * from table2 Select * from @tab1 我正在尝试此查询,但出现错误 请提供帮助。此行出现错误: 将@tab1声明为表 “table”附近的语法不正确 但您的插入也犯了一个错误,应该是: select * into tab1 from table2 据我所知,在使用表变量时需要声明模式,如果使用临时表,则不需要声
Declare @tab1 as table
Insert into @tab1 select * from table2
Select * from @tab1
我正在尝试此查询,但出现错误
请提供帮助。此行出现错误: 将@tab1声明为表 “table”附近的语法不正确 但您的插入也犯了一个错误,应该是:
select * into tab1
from table2
据我所知,在使用表变量时需要声明模式,如果使用临时表,则不需要声明模式,这样就可以了
select * into #tab1
from table2
请参见这将起作用:
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的网站上查找()以获得一些好的建议错误在第一行 Msg 102,15级,状态1,第1行 “table”附近的语法不正确 请尝试将@tab1声明为表,而不是 将@tab1声明为表(col1 varchar(100))即完整表模式 e、 g 将@tab1声明为表(col1 瓦查尔(100)) 插入@tab1选择[人名] 来自tblInformation 从@tab1中选择* 输出: col1 xyz
abc