Is there any way I could optimize the below SQL in DB2 :
The below SQL is a combination of 257 UNION ALL statements. This query works when I m combining less than 255 UNION ALL statements, but fails with the below error when we are trying to execute more than 255 UNION ALL statements.
Error :
THE STATEMENT IS TOO LONG OR TOO COMPLEX. SQLCODE=-101, SQLSTATE=54001, DRIVER=3.63.75 SQL Code: -101, SQL State: 54001
DB2 SQL query :
SELECT
'400005' as COLUMN1,
'DB' as COLUMN2,
'1' AS COLUMN3
FROM sysibm.sysdummy1
UNION ALL
SELECT
'400005' as COLUMN1,
'DB' as COLUMN2,
'2' AS COLUMN3
FROM sysibm.sysdummy1
UNION ALL
.
.
.
.
UNION ALL
SELECT
'400005' as COLUMN1,
'DB' as COLUMN2,
'257' AS COLUMN3
FROM sysibm.sysdummy1
I came across the few link https://www.ibm.com/support/knowledgecenter/en/SSEPEK_10.0.0/codes/src/tpc/n129.html , but they arent much useful.
Any inputs would be helpful.
Thanks !