Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2005

    Unanswered: Declaring a variable.

    I'm using this ( ODBC tool to send ad-hoc queries to a DB2 7.2 server.

    I simply want to declare a variable and use it later.


    declare @iMyVar int
    select * from Tbl1 where Col1 = @iMyVar

    I keep getting a syntax error:
    SQL0104N An unexpected token "@iMyVar" was found following "Declare ". Expected tokens may include: "JOIN <joined_table>". SQLSTATE=42601
    State:42601,Native:-104,Origin:[IBM][CLI Driver][DB2/6000]

    Any help is very much appreciated.

  2. #2
    Join Date
    Jun 2003
    Toronto, Canada
    Provided Answers: 1
    1. You don't need to add "@" to the variable name; see the manual for correct DECLARE syntax;
    2. You can only use DECLARE in a compound statement.

    I doubt your ODBC tool would support compound statements though.

Posting Permissions

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