如何將#temp 表中的資料插入到作為 varchar 變數傳遞的永久表中?
我要求相反的轉移:
Declare @anytable varchar(99)='perma'
--insertexec
Insert into #temptablecreatedalready
Exec('select * from ' @anytable)
uj5u.com熱心網友回復:
不要在查詢字串中單獨添加選擇,而是嘗試整個插入。
Declare @anytable = 'perma'
EXEC(
'Insert into ' @anytable '
select * from #temptablecreatedalready')
確保#temptablecreatedalready在執行查詢字串之前在當前會話中創建該表。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/347756.html
標籤:sql sql-server 查询语句
下一篇:查詢帶有空格條件的XML列
