All Forums Database
Nikhil_Teradata 24 posts Joined 10/13
09 Jun 2015
Variables in TD?

Hi,
I am a TD newcomer and still figuring out details. 
I came across below piece of code that caught my attention.

REPLACE PROCEDURE ABC (IN dbname VARCHAR(30),IN spname VARCHAR(100), IN batchDt DATE ) 
BEGIN

DECLARE tProcDb VARCHAR(30) ;
DECLARE tProcNm VARCHAR(100);
DECLARE tmsg_id, hc1count INTEGER ;
DECLARE sqlmsg VARCHAR(1000);
DECLARE hHex CHAR(2);
DECLARE hAscii, hrepl CHAR(1);

SET tProcDb = dbname;
SET tProcNm = spname;

Are these tProcDb, tProcNm variables? Is this a way to declare and use variables? 
I tried to do this in a separate window.

DECLARE url VARCHAR(1000);
DECLARE id VARCHAR(100);

SET url = 'http://www.ABC.com/CDE/00004537173DA4D4'
SET id = SUBSTRING (url, 5,20))
SELECT id

I got message: The query is invalid.
What am I missing in this picture?

--Nik

"Learn, Learn, Learn and your life would never be boring"

Fred 1096 posts Joined 08/04
09 Jun 2015

You can define and use variables inside a stored procedure definition. You can't do that inline in regular Teradata SQL.

Nikhil_Teradata 24 posts Joined 10/13
10 Jun 2015

Thank you Fred. 

--Nik

"Learn, Learn, Learn and your life would never be boring"

You must sign in to leave a comment.