使用动态变量和CTE(公用表表达式)之间有什么区别
动态:
DECLARE @id nvarchar
SET @id = ( SELECT ID_CHIMQ
FROM Table1
where Name = 'Ben')
EXEC sp_executesql @id
CTE:
WITH cte (Col1, Col2, Col3)
AS
(
SELECT Col1, Col2, Col3
FROM Table
)
SELECT * FROM cte
这两者之间的区别在于何时使用其中一个和性能问题等?
感谢