All you need is

INSERT INTO liba/doc#file
SELECT loc, petable.enddate, outlet,
docfunc(:loc, :outlet, :enddate)
FROM libb/sales JOIN libx/petable
ON sales.year = petable.year
AND sales.period = petable.period
GROUP BY petable.enddate,loc,outlet
ORDER BY 1,2,3

Optionally, you could have
docfunc(:loc, :outlet, :enddate) as docnum

To give the result column a name, but the names don't matter to the insert.
Only size/type.

Charles

Charles


On Wed, Sep 10, 2014 at 10:11 AM, Gary Thompson <gthompson@xxxxxxxxxxx>
wrote:

First, Thank you.
I'm trying to avoid my typical use of an SQL cursor in a program to loop
through
data to get document numbers for sales commissions (my project for today).

Here's a (crude) example of my goal:

-- Load Document # file using SQL Function libf/docfunc
INSERT INTO liba/doc#file
SELECT loc, petable.enddate, outlet,
SET docnum = docfunc(:loc, :outlet, :enddate)
FROM libb/sales JOIN libx/petable
ON sales.year = petable.year
AND sales.period = petable.period
GROUP BY petable.enddate,loc,outlet
ORDER BY 1,2,3
;

From what I know, SET cannot be used this way.
My read of the 7.1 SQL reference says SET is only used to set a host
variable ?

SQL Function docfunc returns a Document Number given: Location, Outlet
and Fiscal Period End Date
Document Number identifies a structure containing sales commission detail
for a fiscal period.
petable stores fiscal period detail




-----Original Message-----
From: MIDRANGE-L [mailto:midrange-l-bounces@xxxxxxxxxxxx] On Behalf Of
rob@xxxxxxxxx
Sent: Wednesday, September 10, 2014 4:53 AM
To: Midrange Systems Technical Discussion
Subject: Re: Limits of SQL SET variable

Let's begin with the end in mind. What is it you are trying to do?


Rob Berendt
--
IBM Certified System Administrator - IBM i 6.1 Group Dekko Dept 1600 Mail
to: 2505 Dekko Drive
Garrett, IN 46738
Ship to: Dock 108
6928N 400E
Kendallville, IN 46755
http://www.dekko.com





From: Gary Thompson <gthompson@xxxxxxxxxxx>
To: Midrange Systems Technical Discussion <midrange-l@xxxxxxxxxxxx>
Date: 09/10/2014 01:40 AM
Subject: Limits of SQL SET variable
Sent by: "MIDRANGE-L" <midrange-l-bounces@xxxxxxxxxxxx>



My limited experience using SET and reading DB2 for i SQL Reference 7.1
leads me to conclude SET can only update the value of a 'host' variable ?

And that SET cannot be used within an SQL Select ?

But, maybe, can be used within an embedded SQL Select where SET is
in a subselect or common table expression ?
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing
list
To post a message email: MIDRANGE-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/midrange-l.


--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list
To post a message email: MIDRANGE-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/midrange-l.

--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list
To post a message email: MIDRANGE-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/midrange-l.



As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
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.