I have to do one query to get one parameter (I need a "1"), but this parameter can be in different cells, for example:
+--------------+--------------+--------------+
|....cell1.....|.....cell2....|....cell3.....|
+--------------+--------------+--------------+
|....here......|.....here.....|....or here...|
+--------------+--------------+--------------+
I have to capture and after, if its equals to one do other query to get what I want. I try to do a procedure with this code:
SET TERM !! ;
CREATE PROCEDURE GET_CASH(
TICKET VARCHAR(15))
RETURNS ( TOTAL integer
)
AS
BEGIN
FOR SELECT a.ID_FPAY1, a.FPAY1_IMPORT, a.ID_FPAY2, a.FPAY2_IMPORT, a.ID_FPAY3, a.FPAY3_IMPORT
FROM TB_TICKETS_HIS a WHERE a.ID_TICKET = TICKET
DO
BEGIN
IF a.ID_FPAY1 = 1 THEN TOTAL = a.FPAY1_IMPORT;
IF a.ID_FPAY2 = 1 THEN TOTAL = a.FPAY2_IMPORT;
IF a.ID_FPAY3 = 1 THEN TOTAL = a.FPAY3_IMPORT;
SUSPEND;
END
END!!
SET TERM ; !!
When execute the query apears this error:
SQL Message : -104
Invalid token
Engine Code : 335544569
Engine Message :
Dynamic SQL Error
SQL error code = -104
Token unknown - line 11, column 5
DO
I try to it works deleting the FOR and Do, appears this error:
SQL Message : -104
Invalid token
Engine Code : 335544569
Engine Message :
Dynamic SQL Error
SQL error code = -104
Token unknown - line 11, column 5
BEGIN
Someone can help me with this procedure or explain me what is failing?