Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 3 of 3 total
Thread How does the INTO Clause of a SELECT Statement Work
Mon, Sep 16 2013 7:30 PMPermanent Link

Michael Riley

ZilchWorks

Avatar

I've been struggling with how to use the INTO Clause of a SELECT
statement. I'm looking for an example of how to implement it within EDB
Manager.

I'd also like to know under what circumstances this might be used.
Thank you in advance for your help.

------------------------------------------
Here is the documentation I found:

http://www.elevatesoft.com/manual?action=viewtopic&id=edb2sql&topic=SELECT

SELECT [ALL|DISTINCT]
*|<SelectColumn> [,<SelectColumn>]
[INTO <OutputParameter>[,<OutputParameter>]]
..
..
..

------------------------------------------

INTO Clause

The INTO clause allows you to specify one or more output parameters as
the target of a SELECT statement. Such a statement doesn't return a
result set at all, which is useful for situations where you only want
one, or a few, values from a specific row in a table.

Note

The use of the INTO clause requires that the SELECT statement only
return a single row. If the SELECT statement returns more than one row,
then an exception will be raised.

------------------------------------------

-- This SELECT statement returns the
-- user-defined version for a given
-- table, or NULL if the table does
-- not exist. It uses the INTO clause
-- to put the resultant value into an
-- output parameter.
SELECT Version INTO :Version
FROM Information.Tables WHERE Name=:Name


--
Michael Riley
GySgt USMC (Ret)
www.zilchworks.com
Tue, Sep 17 2013 3:58 AMPermanent Link

Uli Becker

Michael,

> I've been struggling with how to use the INTO Clause of a SELECT
> statement. I'm looking for an example of how to implement it within EDB
> Manager.

You can use it either in  a script/stored procedure or within delphi. E.g.:

DECLARE FSelected VARCHAR DEFAULT = '';
DECLARE FMyID integer DEFAULT = 1;

Execute Immediate 'Select MyValue INTO ? from MyTable where ID = ?'
using FSelected,FMyID;

DoSomethingWithFSelected...

or in Delphi

with MyQuery do
begin
  sql.clear;
  sql.add('Select MyValue INTO :FSelected from MyTable where ID = :FMyID');
  ParamByName('FMyID').asInteger = 1;
  Open;
end;

DoSomething with ParamByName('FSelected ').asString;

All untested!

Hope that helps...

Regards Uli
Tue, Sep 17 2013 8:53 AMPermanent Link

Michael Riley

ZilchWorks

Avatar

Uli Becker wrote:

<<
You can use it either in  a script/stored procedure or within delphi. E.g.:

DECLARE FSelected VARCHAR DEFAULT = '';
DECLARE FMyID integer DEFAULT = 1;

Execute Immediate 'Select MyValue INTO ? from MyTable where ID = ?'
using FSelected,FMyID;

DoSomethingWithFSelected...

or in Delphi

with MyQuery do
begin
  sql.clear;
  sql.add('Select MyValue INTO :FSelected from MyTable where ID = :FMyID');
  ParamByName('FMyID').asInteger = 1;
  Open;
end;

DoSomething with ParamByName('FSelected ').asString;
>>

Thsnkd Uli

Michael Riley
GySgt USMC (Ret)
www.zilchworks.com
Image