Declaring variables in Terdata SQL Assistant

Database

Declaring variables in Terdata SQL Assistant

Hi,

I'm connected to a DB2 datasource thru TD Sql assistant. I'm writing a simple query to pull purchase order header and detail info for a specific PO number as in the example below. However I'm trying to write it using a variable that will pass a specific PO # that I pass, but I keep getting error message. Below is what I'm running w/o the variable which runs successfully, and with the variable.

SELECT *

from DB.POHDR h

inner join

DB.PODTL d

on h.PO_NBR = d.PO_NBR

WHERE H.PO_NBR = '9389219'

-------------------------------------------

DECLARE VARIABLE PONBR;

SET PONBR = '9389219';

SELECT *

from OD.POHDR h

inner join

OD.PODTL d

on h.PO_NBR = d.PO_NBR

WHERE H.PO_NBR = PONBR

Error msg:  DECLARE failed. 104:  SQL0104N An unexpected token "PONBR" was found following....

4 REPLIES
Teradata Employee

Re: Declaring variables in Terdata SQL Assistant

This is a DB2 question and not Teradata or even SQL Assistant. Is DECLARE VARIABLE even supported via ODBC?

Teradata Employee

Re: Declaring variables in Terdata SQL Assistant

DECLARE VARIABLE is an embedable, non-excutable statement meant for pre-processor (or stored-procedures). See http://www.ibm.com/support/knowledgecenter/SSEPEK_10.0.0/sqlref/src/tpc/db2z_sql_declarevariable.htm...

Like Fred said, you'll get a better response if you post your question in DB2 forums. SQL Assistant is just the "messenger" here :)

Re: Declaring variables in Terdata SQL Assistant

Got it!  Thanks for explanation. This is my first post and I'm a TD newbie, so, since I'm using TD sql assistant to connect to DB2 and queries objects, I thouht it should be submitted under TD.

Re: Declaring variables in Terdata SQL Assistant

Can someone provide the link to the DB2 forum please?