仅举例来说:
With DependencedIncidents AS ( SELECT INC.[RecTime],INC.[SQL] AS [str] FROM ( SELECT A.[RecTime] As [RecTime],X.[SQL] As [SQL] FROM [EventView] AS A CROSS JOIN [Incident] AS X WHERE patindex('%' + A.[Col] + '%', X.[SQL]) > 0 ) AS INC ) With lalala AS ( SELECT INC.[RecTime],INC.[SQL] AS [str] FROM ( SELECT A.[RecTime] As [RecTime],X.[SQL] As [SQL] FROM [EventView] AS A CROSS JOIN [Incident] AS X WHERE patindex('%' + A.[Col] + '%', X.[SQL]) > 0 ) AS INC )
…不起作用。“错误与附近”。
另外,我想先用在里面,再用在里面。是真实的还是我需要使用临时表?
尝试:
With DependencedIncidents AS ( SELECT INC.[RecTime],INC.[SQL] AS [str] FROM ( SELECT A.[RecTime] As [RecTime],X.[SQL] As [SQL] FROM [EventView] AS A CROSS JOIN [Incident] AS X WHERE patindex('%' + A.[Col] + '%', X.[SQL]) > 0 ) AS INC ), lalala AS ( SELECT INC.[RecTime],INC.[SQL] AS [str] FROM ( SELECT A.[RecTime] As [RecTime],X.[SQL] As [SQL] FROM [EventView] AS A CROSS JOIN [Incident] AS X WHERE patindex('%' + A.[Col] + '%', X.[SQL]) > 0 ) AS INC )
是的,您可以在通用表表达式定义内引用通用表表达式。甚至递归地。这导致一些非常巧妙的技巧。