|
David, Try the following. ----- create function historicIntOperand(issueID integer, atom integer, historic timestamp) returns integer language SQL specific historicIntOperand reads sql data begin atomic declare foo int; 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; return foo; end ----- Hope this helps! Richard -----Original Message----- From: midrange-l-bounces@xxxxxxxxxxxx [mailto:midrange-l-bounces@xxxxxxxxxxxx]On Behalf Of David Gibbs Sent: Monday, August 08, 2005 5:06 PM To: Midrange Systems Technical Discussion Subject: SQL function ... this one is for SQL gurus 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 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.