If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Declaring a variable.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-15-06, 18:51
Ivoryzion Ivoryzion is offline
Registered User
 
Join Date: Jun 2005
Posts: 4
Declaring a variable.

I'm using this (http://gpoulose.home.att.net) ODBC tool to send ad-hoc queries to a DB2 7.2 server.

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

Example:

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.
Reply With Quote
  #2 (permalink)  
Old 03-15-06, 21:23
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
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.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On