By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,851 Members | 1,752 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,851 IT Pros & Developers. It's quick & easy.

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

P: 1
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
Share this question for a faster answer!
Share on Google+

Post your reply

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