Archives of the TeradataForum
Message Posted: Fri, 05 Oct 2012 @ 12:25:35 GMT
Subj: | | Re: Stored Procedure: SELECT INTO clause |
|
From: | | Dieter Noeth |
You didn't show the error message, but i assume it's a syntax error. A variable can't be used for any database/table/column name.
You need a cursor with some dynamic SQL, because you can't use SELECT INTO dynamically:
DECLARE sqlstr VARCHAR(1000);
DECLARE c CURSOR FOR s;
SET SqlStr = 'SELECT COUNT(*) INTO :vClient_ID FROM ' || vDBName
|| '.CLIENT_TABLE WHERE CLIENT_CODE = ''ABC''';
PREPARE s FROM SqlStr;
OPEN c;
FETCH c INTO vClient_ID;
CLOSE c;
Dieter
|