All Forums Database
latingntlman 3 posts Joined 08/16
17 Aug 2016
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....

 

Fred 1096 posts Joined 08/04
17 Aug 2016

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

padhia 35 posts Joined 06/10
18 Aug 2016

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.html 
 
Like Fred said, you'll get a better response if you post your question in DB2 forums. SQL Assistant is just the "messenger" here :)

latingntlman 3 posts Joined 08/16
18 Aug 2016

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.

latingntlman 3 posts Joined 08/16
18 Aug 2016

Can someone provide the link to the DB2 forum please?

You must sign in to leave a comment.