Some parts in the output code are omitted for clarity reasons.
Description
When OUTER APPLY is specified, one row is produced for each row of the left rowset even when the right-side rowset expression returns an empty rowset for that row. (OUTER APPLY Definition)
Syntax
Apply_Operator :='CROSS''APPLY' | 'OUTER''APPLY'.
Snowflake equivalence
Despite the unsupported statement OUTER APPLY in Snowflake, there is an equivalent statement which is LATERAL. Hence, the translation for the statement is conducted to get the same functionality through the use of alternative solutions.
Nevertheless, the LATERAL statement in Snowflake has two variations in syntax. In fact, the INNER JOIN LATERAL variation is used in this specific translation.
The INNER JOIN LATERAL grammar from Snowflake is the following:
Since the translation is an equivalence from the input, there are some limitations.
TOP and WHERE statements may be reviewed for optimal behavior.
A correlation name at the end of the statement may be needed. In Snowflake, the query does not represent a problem if the correlation name is not in the query, but functionality may change and does not form part of the accepted pattern in SQL Server.
IN -> SqlServer_02.sql
SELECT SATT.UNIVERSAL_NAMEFROMSAMPLE_ATLAS AS SATTOUTERAPPLY (SELECTTOP1 UNIVERSAL_NAME, INTERNATIONAL_NAME, CODE_IDENTIFIERFROM SAMPLE_GLOBE AS SGWHERE SG.GLOBE_KEY = SATT.MbrPersGenKeyORDER BY GLOBE_KEY);
SELECT UNIVERSAL_NAMEFROM SAMPLE_ATLASAS SATTOUTERAPPLY /*** MSC-ERROR - MSCCP0001 - THE FOLLOWING SUBQUERY MATCHES AT LEAST ONE OF THE PATTERNS CONSIDERED INVALID AND MAY PRODUCE COMPILATION ERRORS ***/ (SELECT TOP 1
UNIVERSAL_NAME, INTERNATIONAL_NAME, CODE_IDENTIFIERFROM SAMPLE_GLOBE AS SGWHERE SG.GLOBE_KEY = SATT.MbrPersGenKeyORDER BY GLOBE_KEY );
Specific statements that are not supported may comment out all the block code (example taken from: JSON Example).
OUT -> SqlServer_02.sql
SELECT SATT.UNIVERSAL_NAMEFROMSAMPLE_ATLAS AS SATTINNER JOIN LATERAL (SELECTTOP1 UNIVERSAL_NAME, INTERNATIONAL_NAME, CODE_IDENTIFIERFROM SAMPLE_GLOBE AS SGWHERE SG.GLOBE_KEY = SATT.MbrPersGenKeyORDER BY GLOBE_KEY);
SELECT familyName, c.givenName AS childGivenName, c.firstName AS childFirstName, p.givenName AS petNameFROM Families fLEFT OUTER JOIN OPENJSON(f.doc) /*** MSC-WARNING - MSCEWI4030 - Equivalence from CROSS APPLY to LEFT OUTER JOIN must be checked. ***/;
-- ** MSC-ERROR - MSCEWI1001 - UNRECOGNIZED TOKEN ON LINE 7 OF THE SOURCE CODE. **-- WITH (familyName nvarchar(100), children nvarchar(max) AS JSON)-- CROSS APPLY OPENJSON(children)-- WITH (givenName nvarchar(100), firstName nvarchar(100), pets nvarchar(max) AS JSON) as c-- OUTER APPLY OPENJSON (pets)-- WITH (givenName nvarchar(100)) as p