2009-10-09 58 views

回答

1

錯誤在第一行

Msg 102,Level 15,State 1,Line 1 'table'附近的語法不正確。

代替申報@ TAB1如表嘗試

申報@ TAB1如表(COL1 VARCHAR(100)),即全表模式

例如

申報@ TAB1如表(COL1 VARCHAR(100))

插入@ TAB1從@從tblInformation

選擇*選擇[用戶名] TAB1

輸出:

個COL1

XYZ
ABC

3

錯誤與該行:

申報@ TAB1如表

附近有語法錯誤 '表'。

,但你也取得了與插入一個錯誤應該是:

select * into tab1 
from table2 

據我知道你需要使用表可變因素時,申報方案,如果使用臨時表你不」牛逼所以這會工作

select * into #tab1 
from table2 

msdn

0

這將工作:

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)以獲得一些好的建議

相關問題