× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



David, 
with this statement he is likely to be returning a UDTF (User Defined Table
Function) - result set, many values. 
His UDF declaration states that he really wants to return an integer (valid
for UDFs) - single value.

Raul's suggestion is a good solution.

Also, 'into foo' part seems out of place.

There is a very good redbook on this topic: "Stored Procedures, Triggers and
User Defined Functions on DB2 Universal Database for iSeries".

Elvis


-----Original Message-----
 Subject: Re: SQL function ... this one is for SQL gurus

 From your definition I assume the function should return an integer, if 
so try:

select min(inOperand)...

David Gibbs wrote:

>I'm posting this for a co-worker ...
>
>He's trying to create a SQL user defined function ...
>
>-----
>create function historicIntOperand(issueID integer, atom integer,
>    historic timestamp)
>    returns integer
>    language SQL
>    specific historicIntOperand
>    reads sql data
>begin atomic
>    return (
>        select IntOperand into foo from IssueDeltas
>            join IssueDeltaAtoms on IssueDeltas.ID =
>IssueDeltaAtoms.ParentID
>            where (IssueDeltas.ParentID = issueID
>            and CreatedDate <= historic
>            and AtomID = atom)
>            order by CreatedDate DESC
>            fetch first 1 row only);
>end
>
>-----
>
>The problem is this ...
>
>Return takes an expression.
>Well, an expression is allowed to be (scalar subselect),
>so we need () around the select.
>Then we get an error when it hits the keyword ORDER.
>A scalar subselect is a subselect.  It is not a select statement.
>A select statement is a fullselect which can be followed by an orderby;
>but a subselect may not have an order by!
>
>The specific error we're getting is: [SQL0199] Keyword ORDER not
>expected. Valid tokens: ) UNION.
>
>We're using V5R3.
>
>Any suggestions?
>
>
>Thanks!
>
>david




As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.