[英]How to Truncate a Table with Partitions?
我正在嘗試使用分區截斷表。
SET @Sql =( 'TRUNCATE TABLE _result.result
WITH (PARTITIONS (SELECT PartitionNumber FROM #temp2 ))
GO');
Exec sp_executesql @sql
而且,我收到此錯誤。
Msg 156, Level 15, State 1, Line 4
Incorrect syntax near the keyword 'SELECT'.
Msg 102, Level 15, State 1, Line 4
Incorrect syntax near ')'.
在我的臨時表中有很多 PartitionNumber,這就是為什么我在 Partitions 中使用 select 語句。
您將需要構造沒有嵌套select
的語句:
SET @SQL = '
TRUNCATE TABLE _result.result
WITH (PARTITIONS [partitions])';
SET @SQL = REPLACE(@SQL, '[partitions]',
STRING_AGG(PartitionNumber, ', ')
)
FROM #temp2;
Exec sp_executesql @sql
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.