I am trying to get multiple WITH statements to work with Azure SQL database, and according to all I found online, this syntax should work, but I get an error:
Msg 102, Level 15, State 1, Line 12
Incorrect syntax near ')'.
SQL:
WITH EpicBenefitsData1 ("Epic Benefits Field Name", "Epic Benefits Field Value", "FK Epic ID") AS
(
SELECT
"Epic Benefits Field Name", "Epic Benefits Field Value", "FK Epic ID"
FROM
[current_dw].[Epic Benefits] AS EpicBenefits1
WHERE
EpicBenefits1.[Epic Benefits Field Set Name] = 'Default'
),
EpicBenefitsData2 ("Epic Benefits Field Name", "Epic Benefits Field Value", "FK Epic ID") AS
(
SELECT
"Epic Benefits Field Name", "Epic Benefits Field Value", "FK Epic ID"
FROM
[current_dw].[Epic Benefits] AS EpicBenefits2
WHERE
EpicBenefits2.[Epic Benefits Field Set Name] = 'FOOBAR'
)
The error is on the ")" on the last line.
I've tried many different ways, trying UNION between the two, multiple WITHs and not, omitting the first 3 parameters and not, but I always get this error in Azure Data Studio.
Any help would be appreciated. I need to use a PIVOT on the data later, but this part has to work first.
Tried many different variants of WITH syntax, with no luck.
1条答案
按热度按时间z2acfund1#
You aren't using your CTE.
A CTE on its own is not a valid query, you need to actually
select
data from your CTE.