|
-----Original Message-----
From: midrange-l-bounces@xxxxxxxxxxxx
[mailto:midrange-l-bounces@xxxxxxxxxxxx] On Behalf Of Jeff Crosby
Sent: Tuesday, August 28, 2007 3:59 PM
To: 'Midrange Systems Technical Discussion'
Subject: SQL pat my own back
I probably ask more SQL how-to questions here than everyone
else combined, so I had to tell you I figured out a
relatively complex one (at least for
me) by myself.
I need to set up a transaction file that's going to be FTPed
to another company. I started writing a cursor driven SQLRPG
program because the data to be gathered needed to come from 4
different files, and the fields massaged somewhat. Then I
remembered someone (Charles Wilt?) saying that if you were
using a cursor in SQL, you were probably doing something
wrong. So I stopped and pondered for a while. Then I came
up with this (below) and it works!
Exec SQL Insert into INSTLTRN
(Select :RptDate,
c.DCNBR,
s.CUSNR,
s.INVNRP,
s.INVDT,
c.INVTRNCD,
s.QTYSH,
Case S.UNITS
When 'U' Then i.QSUN2
Else i.QSUN1
End As QTYUOM,
0,
s.ITNSA/s.QTYSH,
s.ITNSA,
s.ITNBR,
i.ITDSC,
i.PACKX,
i.SIZEX,
i.BRAND,
v.VNDNM,
i.VNITM,
Cast(i.ADUNQ As Char(1)) ConCat
Cast(i.VUPCD As Char(5)) ConCat
Cast(i.IUPCD As Char(5)),
0,
c.PRGCODE
From SAHISTW S
Join INSTLCTL c
On '1' = c.KEYID
Join DMITMMST I
On s.ITNBR = i.ITNBR
Join DMVDRMST V
On s.VNDNR = v.VNDNR
Where s.VNDNR = c.vndnr and
s.INVDT >= :BgnSlsDate and
s.INVDT <= :EndSlsDate and
s.QTYSH > 0);
Host variables and all. And it runs fast.
I get an extra beer tonight.
--
Jeff Crosby
UniPro FoodService/Dilgard
P.O. Box 13369
Ft. Wayne, IN 46868-3369
260-422-7531
The opinions expressed are my own and not necessarily the
opinion of my company. Unless I say so.
--
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 mailing list archive is Copyright 1997-2025 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.