select failed 3707 expected something like an 'EXCEPT' keyword or an 'UNION' keyword or a 'MINUS' keyword between an integer and

General

select failed 3707 expected something like an 'EXCEPT' keyword or an 'UNION' keyword or a 'MINUS' keyword between an integer and

Hi All,

I am executing the following query on a table A in db DB, where the schema of table A consists of M_ID and USD_M1_AMT, USD_M2_AMT and USD_M3_AMT and these are USD amounts for three separate months. I need to sum the 3 amounts for each row corresponding to a unique M_ID in the table A. I have written the below Teradata SQL statement but am facing the error

"select failed 3707 expected something like an 'EXCEPT' keyword or an 'UNION' keyword or a 'MINUS' keyword between an integer and ';'"

My SQL statement is below:

select T.ALL_3M_ID , sum ( T.USD_SUM3AMT )
from
(
select a.M_ID , a.USD_M1_AMT M1_AMT
from
DB.A as "a" INNER JOIN DB.A as "a1" ON a.M_ID = a1.M_ID
UNION ALL
select b.M_ID , b.USD_M2_AMT M2_AMT
from
DB.A as "b" INNER JOIN DB.A as "b1" ON b.M_ID = b1.M_ID
UNION ALL
select c.M_ID , c.USD_M3_AMT M3_AMT
from
DB.A as "c" INNER JOIN DB.A as "c1" ON c.M_ID = c1.M_ID;

) T ( ALL_3M_ID , USD_SUM3AMT )

GROUP BY T.ALL_3M_ID;

Any help will be greatly appreciated.

Thanks
1 REPLY

Re: select failed 3707 expected something like an 'EXCEPT' keyword or an 'UNION' keyword or a 'MINUS' keyword between an integer and

I have made one change and the problem is solved as it seems. Below is the change I did:

select ALL_3M_ID , sum ( USD_SUM3AMT )
from
(
select a.M_ID , a.USD_M1_AMT M1_AMT
from
DB.A as a INNER JOIN DB.A as a1 ON a.M_ID = a1.M_ID
UNION ALL
select b.M_ID , b.USD_M2_AMT M2_AMT
from
DB.A as b INNER JOIN DB.A as b1 ON b.M_ID = b1.M_ID
UNION ALL
select c.M_ID , c.USD_M3_AMT M3_AMT
from
DB.A as c INNER JOIN DB.A as c1 ON c.M_ID = c1.M_ID
ORDER BY 1
) T ( ALL_3M_ID , USD_SUM3AMT )
GROUP BY ALL_3M_ID;

Hope this is fine.

Thanks