Sqlserver
 sql >> Datenbank >  >> RDS >> Sqlserver

Kann ich mehrere mit verwenden?

Versuchen Sie:

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
)

Und ja, Sie können auf allgemeine Tabellenausdrücke innerhalb der allgemeinen Tabellenausdrucksdefinition verweisen. Sogar rekursiv. Was zu einigen sehr sauberen Tricks .