I have issued the SQL statement below :
SELECT GATNR
,GITNO
,GBANO
,MAX (CASE WHEN GATID = 'GR' THEN GATVN ELSE NULL END) AS GR
,MAX (CASE WHEN GATID = 'SZ' THEN GATVN ELSE NULL END) AS SZ
FROM TABLEA AS X
INNER JOIN
(
(
SELECT MAX(GATNR)AS GATNR,GBANO
FROM TABLEA
GROUP BY GBANO
)
INNER JOIN
(
SELECT *
FROM TABLEB
) AS B
ON B.TBANO = GBANO
) AS Y
ON Y.GATNR = X.GATNR
WHERE
GITNO LIKE 'F%'
GROUP BY X.GATNR, X.GITNO, X.GBANO
For some reason, it failed to run & generated the following error messages:
Msg 156, Level 15, State 1, Line 13 Incorrect syntax near the keyword
‘INNER’.
Msg 156, Level 15, State 1, Line 16 Incorrect syntax near the
keyword ‘AS’.
I’m unable to resolve it. Can someone help me to correct the statement ?
I think you want something like this:
It’s hard to know without seeing your schema, though.