Subject | Stored procedure and Select |
---|---|
Author | Matteo Giacomazzi |
Post date | 2002-07-09T13:58:01Z |
Hi all,
there's a thing I cannot understand with SP.
Let's say I have a SP that should return some results on the basis
of a SELECT query.
This SELECT may return more than one result but I'm interested only
in the first one for my computation.
Well, if the SELECT returns more than one row, my SP won't return
anything!
If I change my SP so that the SELECT query will return only one
result, then my SP returns the expected result.
EXAMPLE:
===================================================================
TABLE_1
ID FIELD_1 FIELD_2
1 'Test' 134
2 'Another Test' 12
3 'Last test' 4
CREATE PROCEDURE TEST
RETURNS (ID SMALLINT, FIELD_1 VARCHAR(20), FIELD_2 INTEGER)
AS
BEGIN
SELECT *
FROM TABLE_1
INTO :ID, :FIELD_1, :FIELD_2;
SUSPEND;
END
===================================================================
Well, if I perform
SELECT * FROM TEST;
I won't get anything.
If I add to its inner SELECT a clause such as
WHERE ID = 2
It works and returns (2, 'Another Test', 12).
Why that?
Thank you in advance!
Kind regards,
--
Matteo
mailto:matteo.giacomazzi@...
ICQ# 24075529
there's a thing I cannot understand with SP.
Let's say I have a SP that should return some results on the basis
of a SELECT query.
This SELECT may return more than one result but I'm interested only
in the first one for my computation.
Well, if the SELECT returns more than one row, my SP won't return
anything!
If I change my SP so that the SELECT query will return only one
result, then my SP returns the expected result.
EXAMPLE:
===================================================================
TABLE_1
ID FIELD_1 FIELD_2
1 'Test' 134
2 'Another Test' 12
3 'Last test' 4
CREATE PROCEDURE TEST
RETURNS (ID SMALLINT, FIELD_1 VARCHAR(20), FIELD_2 INTEGER)
AS
BEGIN
SELECT *
FROM TABLE_1
INTO :ID, :FIELD_1, :FIELD_2;
SUSPEND;
END
===================================================================
Well, if I perform
SELECT * FROM TEST;
I won't get anything.
If I add to its inner SELECT a clause such as
WHERE ID = 2
It works and returns (2, 'Another Test', 12).
Why that?
Thank you in advance!
Kind regards,
--
Matteo
mailto:matteo.giacomazzi@...
ICQ# 24075529