SQL0104 Token Col_Name was not valid

1.2k views Asked by At

I am trying to update TableA with the below query and it gives me an error "IBM.Data.DB2.iSeries.iDB2SQLErrorException: 'SQL0104 Token CNUM was not valid. Valid tokens: USE SKIP WAIT WITH FETCH LIMIT ORDER WHERE OFFSET". Though i am able to update the database with the same query in DB2.

using (IDbCommand command = this.connection.CreateCommand())
{
    command.CommandText = string.Format(
        @"UPDATE {0}.TableA
        SET
        STS = @Status,
        USR = @User
        WHERE 
        CNUM = @CNum", CoreServer.CoreCollection);

    IDbDataParameter statusParam = CoreServer.CreateParameter(command, "@Status", string.Empty, 3);
    IDbDataParameter UserParam = CoreServer.CreateParameter(command, "@User", string.Empty, 50);
    IDbDataParameter cNumberParam = CoreServer.CreateParameter(command, "@CNum", string.Empty, 30);

    statusParam.Value = CoreServer.ConvertToDatabase(input.Status);
    UserParam.Value = input.User == null ? null : input.User.Trim();
    cNumberParam.Value = input.CNumber.Trim();

    iDB2Command db2Command = (iDB2Command)command;
    db2Command.Transaction = (iDB2Transaction)transaction;
    db2Command.ExecuteNonQuery();
}

Other Insert and Select queries works fine for the same table

1

There are 1 answers

0
D. Kermott On

I got this error when I did a copy/paste of the sql where some sort of non-printable character was present.

To narrow down the problem I:

  • replaced the sql with something simple... like "select * from myTable"
  • removed as much of the query text as possible
  • put pieces back in gradually and tested after each step
  • put the sql into a hex-text editor (or regular editor and replaced spaces with * and then looked for something that looked like a space)