Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2014
    Posts
    294

    Unanswered: SQLSTATE=42816 error with only one database, working fine with other

    Hi ,

    I am trying to perform some date operations. I can able to query this on one database, If i ran the same query on other database it is failing with an error.Don't know what i have to change & where it is going wrong.

    db2 => CONNECT TO LOL

    Database Connection Information

    Database server = DB2/NT64 10.5.1
    SQL authorization ID = GHTY...
    Local database alias = LOL

    db2 => SELECT VARCHAR_FORMAT((DATE('19/09/1949') + 1),'DD/MM/YYYY') FROM SYSIBM.SYSDUMMY1

    1
    ----------------------------------------------------------------------------------------------
    20/09/1949

    1 record(s) selected.

    db2 =>
    db2 =>
    db2 =>
    db2 =>
    db2 =>
    db2 =>
    db2 => CONNECT RESET
    DB20000I The SQL command completed successfully.
    db2 =>
    db2 =>
    db2 => CONNECT TO SAMPLE

    Database Connection Information

    Database server = DB2/NT64 10.5.1
    SQL authorization ID = GHTY...
    Local database alias = SAMPLE

    db2 => SELECT VARCHAR_FORMAT((DATE('19/09/1949') + 1),'DD/MM/YYYY') FROM SYSIBM.SYSDUMMY1
    SQL0182N An expression with a datetime value or a labeled duration is not
    valid. SQLSTATE=42816
    db2 =>

  2. #2
    Join Date
    Apr 2006
    Location
    Belgium
    Posts
    2,514
    Provided Answers: 11
    DATE('19/09/1949') is not save eg DATE('02/09/1949') what is month - what is day
    always use YYYY-MM-DD as standard date format
    Best Regards, Guy Przytula
    Database Software Consultant
    Good DBAs are not formed in a week or a month. They are created little by little, day by day. Protracted and patient effort is needed to develop good DBAs.
    Spoon feeding : To treat (another) in a way that discourages independent thought or action, as by overindulgence.
    DB2 UDB LUW Certified V7-V8-V9-V9.7-V10.1-V10.5 DB Admin - Advanced DBA -Dprop..
    Information Server Datastage Certified
    http://www.infocura.be

  3. #3
    Join Date
    Apr 2012
    Posts
    1,035
    Provided Answers: 18
    Additionally you need to correct your syntax (i.e. +1 is ambiguous, 1 what unit?)

    It's not necessary to select from sysibm.sysdummy1 - you can simply use the values clause.

    For example:
    db2 "values VARCHAR_FORMAT((DATE('19/09/1949') + 1 day),'DD/MM/YYYY')"

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •