views:

79

answers:

1

I'd like to get the ID of a particular row from within a Firebird 2.1 stored procedure. I can't seem to remember the syntax, and it's driving me nuts.

This is how the code might look in TSQL, used by Microsoft SQL Server.

    @ID = SELECT ID FROM ADDRESS WHERE 
      POBox = :POBOX AND
      ExtendedAddress = :EXTENDEDADDRESS AND
      StreetAddress = :STREETADDRESS AND
      Locality = :LOCALITY AND
      Region = :REGION AND
      PostalCode = :POSTALCODE AND
      CountryName = :COUNTRYNAME;

What's the Firebird equivalent?

UPDATE: The Firebird SQL migration guide suggests that this should work

    SELECT ID INTO :ID FROM ADDRESS WHERE 
      POBox = :POBOX AND
      ExtendedAddress = :EXTENDEDADDRESS AND
      StreetAddress = :STREETADDRESS AND
      Locality = :LOCALITY AND
      Region = :REGION AND
      PostalCode = :POSTALCODE AND
      CountryName = :COUNTRYNAME;

But I get a syntax error at "INTO" when I try to create the stored proc.

+3  A: 

Apparently, the Firebird migration guide is wrong. This syntax worked for me:

SELECT ID FROM ADDRESS WHERE 
   POBox = :POBOX AND
   ExtendedAddress = :EXTENDEDADDRESS AND
   StreetAddress = :STREETADDRESS AND
   Locality = :LOCALITY AND
   Region = :REGION AND
   PostalCode = :POSTALCODE AND
   CountryName = :COUNTRYNAME
INTO :ID;

Note that the INTO clause must come after the FROM and WHERE clauses.

dthrasher
I'm pretty sure the semicolon after `:COUNTRYNAME` is wrong.
mghie
You're right, @mghie! Silly cut and paste error. I've corrected my answer.
dthrasher