SonarQube. Parse error in CROSS APPLY with union but all looks good

I have file with sql function about 1k lines. Sonar throws an error on this file. The code itself works without errors. Here is a general view of the request where the error. Parse error message points to symbol above '^'

 INSERT INTO foo
SELECT
  ...
FROM foo
JOIN ..
JOIN ...
CROSS APPLY (SELECT TOP (1)
    ...
  FROM ...
  WHERE ...
  ORDER BY ..
  UNION
  ^
  SELECT TOP (1) 
    ...
  FROM ...
  JOIN ...
  JOIN ...
  WHERE ...
  ORDER BY ...
) pp

1 answer

  • answered 2021-02-27 05:43 Kazi Mohammad Ali Nur

          INSERT INTO foo
            SELECT
              ...
            FROM foo
            JOIN ..
            JOIN ...
            CROSS APPLY ((SELECT TOP (1)
                ...
              FROM ...
              WHERE ...
              ORDER BY ..)
              UNION
              ^
    (          SELECT TOP (1) 
                ...
              FROM ...
              JOIN ...
              JOIN ...
              WHERE ...
              ORDER BY ..)
            ) pp