开发者

Using EXEC() or SP_EXECUTESQL with SQL Common Table Expressions

开发者 https://www.devze.com 2023-03-21 14:06 出处:网络
How do I use EXEC(@SQL) or EXEC SP_EXECUTESQL(@SQL) with Common Table Expressions? Below does not work.

How do I use EXEC(@SQL) or EXEC SP_EXECUTESQL(@SQL) with Common Table Expressions?

Below does not work.

WITH C开发者_JAVA技巧TE_Customer (ID,  Name)
AS
(
    EXEC (@strSqlCommand)
)


The short answer is that you cant:

http://msdn.microsoft.com/en-us/library/ms175972.aspx says: "The CTE_query_definition must meet the same requirements as for creating a view" Which basically says that you're restricted to SELECT statements only.

Some workarounds might include using temp tables or table variables, but it really depends on context.

0

精彩评论

暂无评论...
验证码 换一张
取 消