0

In linux i connected to DB2 and trying to grab oldest invoice. while using this below query it shows an error SQL0206N "INVOICEDATE" is not valid in the context where it is used.SQLSTATE=42703

db2 "select min(INVOICEDATE) from RHA2";

How can I resove this error . any help?

Thanks in advance.

1
  • I guess your column is actaully called e.g. InvoiceDate or some such mixed or lower case name , in which case, try db2 'select min("InvoiceDate") from RHA2' Commented Mar 23, 2020 at 23:22

1 Answer 1

1

$ db2 "? sql206"

SQL0206N "" is not valid in the context where it is used.

Explanation:

This error can occur in the following cases:

  • For an INSERT or UPDATE statement, the specified column is not a column of the table, or view that was specified as the object of the
    insert or update.

  • For a SELECT or DELETE statement, the specified column is not a column of any of the tables or views identified in a FROM clause in
    the statement.

  • For an assignment statement, the reference name does not resolve to the name of a column or variable.

  • When referencing a field in a row type variable, the reference name does not resolve to the name of any field in the row type.

  • For an ORDER BY clause, the specified column is a correlated column reference in a subselect, which is not allowed.

  • For a SELECT statement in a parameterized cursor constructor, the reference to "" does not match a column or in-scope variable. Local variables and routine SQL parameters are not considered in scope for parameterized cursors.

  • For a standalone compound SQL (compiled) statement:

    • The reference "" does not resolve to the name of a column or local variable that is in scope.

    • The condition name "" specified in the SIGNAL statement has not been declared.

    • When referencing a field in a row type variable, the reference name does not resolve to the name of any field in the row type.

  • For a CREATE TRIGGER,CREATE METHOD,CREATE FUNCTION or CREATE PROCEDURE statement:

    • The reference "" does not resolve to the name of a column, local variable or transition variable.

    • The reference "" resolves to the name of a local variable that is not available in the current scope.

    • The condition name "" specified in the SIGNAL statement has not been declared.

    • When referencing a field in a row type variable, the reference name does not resolve to the name of any field in the row type.

  • For a CREATE TRIGGER statement:

    • A reference is made to a column of the subject table without using an OLD or NEW correlation name.

    • The left hand side of an assignment in the SET transition-variable statement in the triggered action specifies an old transition variable where only a new transition variable is supported.

  • For a CREATE FUNCTION statement with a PREDICATES clause:

    • The RETURN statement of the SQL function references a variable that is not a parameter or other variable that is in the scope of the RETURN statement.

    • The FILTER USING clause references a variable that is not a parameter name or an expression name in the WHEN clause.

    • The search target in an index exploitation rule does not match some parameter name of the function that is being created.

    • A search argument in an index exploitation rule does not match either an expression name in the EXPRESSION AS clause or a parameter name of the function being created.

  • For a CREATE INDEX EXTENSION statement, the RANGE THROUGH clause or the FILTER USING clause references a variable that is not a parameter name that can be used in the clause.

  • For a parameterized cursor variable reference, a local SQL variable or SQL parameter referenced in the select statement used in the
    definition of a parameterized cursor variable is not available in the current scope.

  • For a period reference, the specified period is not in any of the source or target tables or views of the statement.

The statement cannot be processed.

User response:

Verify that the names are specified correctly in the SQL statement. For a SELECT statement, ensure that all the required tables are named in the FROM clause. For a subselect in an ORDER BY clause, ensure that there are no correlated column references. If a correlation name is used for a table, verify that subsequent references use the correlation name and not the table name.

For a CREATE TRIGGER statement, ensure that only new transition variables are specified on the left hand side of assignments in the SET transition-variable statement and that any reference to columns of the subject table have a correlation name specified.

For a standalone compound SQL statement, CREATE FUNCTION, CREATE PROCEDURE, or CREATE TRIGGER statement, verify that the columns or variables are available in the scope of the current compound SQL statement.

For a fullselect embedded in XQuery using the db2-fn:sqlquery function, a reference within the fullselect must be one of the following: a column in the context of the fullselect, a global variable, or a parameter passed to the new SQL context using an additional argument of the db2-fn:sqlquery function.

sqlcode: -206

sqlstate: 42703

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .