+ Reply to Thread
Results 1 to 3 of 3

Insert Statement with DB2 CLI ODBC - TIMESTAMP Problem

  1. Insert Statement with DB2 CLI ODBC - TIMESTAMP Problem

    Hello!

    I try to insert into a table a timestamp variable.
    i declared a char* in C, and use the following insert statement:

    "INSERT INTO DATE (ID,DATE) VALUES (?,?)"

    Date is a timestamp.
    The SQLBind uses a SQL_C_TYPE_TIMESTAMP.
    My question: how Can i Convert the char* in the format: "11.10.2006" to a TIMESTAMP, so that maybe the error below would be gone?

    SQLCODE = -99999, SQLSTATE = 22001
    MESSAGE: [unixODBC][IBM][CLI Driver] CLI0109E String data right truncation. SQLSTATE=22001

    Thanks, Klaus

  2. Re: Insert Statement with DB2 CLI ODBC - TIMESTAMP Problem

    I donīt know much about i think you could try this:

    To convert a character string to a date or time value, you can use:

    TIMESTAMP ('2002-10-20-12.00.00.000000')
    TIMESTAMP ('2002-10-20 12:00:00')
    DATE ('2002-10-20')
    DATE ('10/20/2002')
    TIME ('12:00:00')
    TIME ('12.00.00')

    So before the inser command execute
    sscanf( string, "%d-%d-%dT%d:%d:%d%c", /* ... */ );
    to format the date like this '2002-10-20 12:00:00'

    then execute the insert:
    INSERT INTO DATE (ID,TIMESTAMP(DATE)) VALUES (?,?)


  3. Re: Insert Statement with DB2 CLI ODBC - TIMESTAMP Problem

    I tried to use the insert statement as follows:
    char *DATUM="2006-11-11 00:00:00";

    "INSERT INTO DATUM (ID,DATUM) VALUES (?, TIMESTAMP_FORMAT(?,'YYYY-MM-DD HH24:MIS')";

    using the SQL_C_TYPE_TIMESTAMP for the SQLBINDPARAMETER( )


    Error code:
    SQLCODE = -99999, SQLSTATE = 22008
    MESSAGE: [unixODBC][IBM][CLI Driver] CLI0113E SQLSTATE 22007: An invalid datetime format was detected; that is, an invalid string representation or value was specified. SQLSTATE=22007

    what's the problem of this statement above? If I make an insert on the Command Line, it is possible as above.


    thanks!
    Klaus

+ Reply to Thread