467,179 Members | 1,197 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,179 developers. It's quick & easy.

Use of SELECT [Fields] INTO [var] in UDFs

Hi,

I have a problem creating the function below:
CREATE FUNCTION TaskProgress (
PROJETO VARCHAR(10),
REVISAO VARCHAR(4),
TAREFA VARCHAR(12)
)
RETURNS DECIMAL(5,2)
LANGUAGE SQL
MODIFIES SQL DATA
NOT DETERMINISTIC
NO EXTERNAL ACTION
SPECIFIC TaskProgress
BEGIN ATOMIC
--------------------------------------------------------------------------------------
-- DECLARACAO DE VARIAVEIS DA FUNCAO --
--------------------------------------------------------------------------------------
DECLARE iResult DECIMAL(5,2) DEFAULT 0;
DECLARE nQtdTot DOUBLE DEFAULT 0;
DECLARE nQtd DOUBLE DEFAULT 0;
--------------------------------------------------------------------------------------
-- PROCURA QTD PLANEJADA NAS TAREFAS --
--------------------------------------------------------------------------------------
SELECT AF9.AF9_QUANT
INTO nQtd
FROM AF9010 AF9
WHERE AF9.AF9_PROJET = PROJETO AND
AF9.AF9_REVISA = REVISAO AND
AF9.AF9_TAREFA = TAREFA AND
AF9.D_E_L_E_T_ <> '*';
--------------------------------------------------------------------------------------
-- CALCULA PERCENTUAL EXECUTADO --
--------------------------------------------------------------------------------------
SET iResult = Round( ( nQtd / nQtdTot ) * 100, 2);
RETURN iResult;
END

The error message when i try to create this function is : "DB2 SQL error: SQLCODE: -104, SQLSTATE: 42601, SQLERRMC: nQtd;INTO;<space>
Message: An unexpected token "nQtd" was found following "INTO". Expected tokens may include: "<space>".
Line: 23"

I guess this is related to the use of SELECT [field] INTO [var] construction for my SQL statement. I checked some DB2 documentation and didnīt find any issues related to the use of this kind of statement.

Could anybody help me to find what i am doing wrong?

Hugs
Aug 22 '07 #1
  • viewed: 868
Share:

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by Shawn Modersohn | last post: by
4 posts views Thread by bobsawyer@gmail.com | last post: by
22 posts views Thread by MP | last post: by
17 posts views Thread by trose178@gmail.com | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.