0
SELECT
     SUBSTR(CAST(YEAR(SOMEDATE) AS VARCHAR(4)),2,2) AS "YY" 
FROM SOMESCHEMA.FOO;

Gets me the following error:

  1. [Code: -104, SQL State: 42601] ILLEGAL SYMBOL ",2". SOME SYMBOLS THAT MIGHT BE LEGAL ARE:. SQLCODE=-104, SQLSTATE=42601, DRIVER=4.26.14
  2. [Code: -514, SQL State: 26501] THE CURSOR SQL_CURLH200C1 IS NOT IN A PREPARED STATE. SQLCODE=-514, SQLSTATE=26501, DRIVER=4.26.14

And no matter what I change, the error stays..

Pwnstar
  • 2,333
  • 2
  • 29
  • 52
  • how are you submitting the SQL? From which tool? Some details missing from question. If you try with an interactive SQL tool , and adjust the query to replace SOMEDATE by CURRENT DATE (just for testing), and replace the table name by `sysibm.sysdummy1` (just for testing), you may get more details. Sometimes, what gets executed is not what you assume. – mao Oct 23 '20 at 10:49
  • I use DBVisualizer. Seems unlikely that this simple SQL statement is not executed correctly. – Pwnstar Oct 23 '20 at 10:52
  • Does the statement run when submitted via a different non-java tool , for example via odbc or CLI, or directly via ISPF or DB2I, SPUFI etc. ? – mao Oct 23 '20 at 11:02

1 Answers1

0

The solution for DB2 z/OS is:

VARCHAR_FORMAT(SOMEDATE, 'YY') AS "YY"
Pwnstar
  • 2,333
  • 2
  • 29
  • 52