Subject Re: I can't find the error in this very short SP
Author Adam
Mark,

I am glad you have found a solution / work around to the issue, but I
think what IBEasy would have been complaining about is the SQL
termintator character (default ';') being found within a statement.

In other words it finds a semi colon and tries to run this as a query

CREATE PROCEDURE SP_PLAYERFIND ( PLAYERNAME VARCHAR(16) )
RETURNS ( PLAYERKEY NUMERIC(15,0) )
AS
BEGIN
SELECT PKEY FROM PLAYERS WHERE PLAYERNAME=:PLAYERNAME
INTO :PLAYERKEY;

If you were a database engine and got fed this you to would kick up a
fuss.

The easiest solution is to do something like this.

-- Change terminator to something else
SET TERM ^;

CREATE PROCEDURE SP_PLAYERFIND ( PLAYERNAME VARCHAR(16) )
RETURNS ( PLAYERKEY NUMERIC(15,0) )
AS
BEGIN
SELECT PKEY FROM PLAYERS WHERE PLAYERNAME=:PLAYERNAME
INTO :PLAYERKEY;
SUSPEND;
END
^

-- Change the terminator back
SET TERM ;
^

By the way, if you have multiple players with the same name, you can
change your procedure slightly to return them all.

CREATE PROCEDURE SP_PLAYERFIND ( PLAYERNAME VARCHAR(16) )
RETURNS ( PLAYERKEY NUMERIC(15,0) )
AS
BEGIN
FOR SELECT PKEY FROM PLAYERS WHERE PLAYERNAME=:PLAYERNAME
INTO :PLAYERKEY
DO
BEGIN
SUSPEND;
END
END
^

Then you could run

Select PlayerKey
from SP_PlayerFind('John Brown');

and it would return something like

PlayerKey
=========
2323
8472721

etc

Otherwise with your first syntax, you should use the first syntax to
be confident you don't get duplicates and hence a SQL error as Helen
pointed out.

ie:

SELECT FIRST 1 PKEY FROM PLAYERS WHERE PLAYERNAME=:PLAYERNAME
INTO :PLAYERKEY;

Adam