I need to extract data from the UNIX system we have and populate a SQL server database. Every day my DTS packages import the flat files that are pushed to the SQL server and insert into or update the database for the past few days. I don't actually have access to the UNIX box, but instead provide scripts to the on staff UNIX guy. However, I'm having a most difficult time trying to retreive data where I need a "group by" clause. Most of the code is very simple; similar to:
DEFINE BUFFER buys FOR BF.buys.
OUTPUT TO /buys.txt.
main-loop:
FOR EACH BF.buys NO-LOCK
WHERE BF.buys.BuyDate GE BegDtParam
AND BF.buys.BuyDate LE EndDtParam:
PUT CONTROL
BF.buys.cust#
"|"
BF.buys.sale#
"|"
BF.buys.BuyDate
"|"
BF.buys.cashier
"|"
BF.buys.item#
CHR(13) CHR(10).
END.
RETURN.
Say we run a beach front business that sells items such as gum, candy, and drinks and also services such as surfing lessons. Patrons purchase only one thing at a time so they often have many sales in a day. The Progress db system keeps track of each beach sale and also constantly updates a current trip table with daily patron totals. A patron comes in 2 months later and says he received bad surfing instructions. The 2 month old sale entry is changed to 1/2 price, which changes his trip data for that day 2 months ago. The system does not include a record change date in the trip table. There is however a record change date in the buys table. I know this is bad bookkeeping, but it illustrates what I'm trying to do.
The SQL code I would use is this:
SELECT Trips.Cust#, Trips.TripDate
FROM Buys INNER JOIN Trips ON
buys.Cust# = Trips.Cust#
AND Buys.BuyDate = Trips.TripDate
GROUP BY Buys.Cust#, Buys.BuyDate,Trips.Cust#, Trips.TripDate, Buys.RecordDate
HAVING Buys.RecordDate between '2007-01-25' and '2007-01-31'
Can anyone help me (please!)?
DEFINE BUFFER buys FOR BF.buys.
OUTPUT TO /buys.txt.
main-loop:
FOR EACH BF.buys NO-LOCK
WHERE BF.buys.BuyDate GE BegDtParam
AND BF.buys.BuyDate LE EndDtParam:
PUT CONTROL
BF.buys.cust#
"|"
BF.buys.sale#
"|"
BF.buys.BuyDate
"|"
BF.buys.cashier
"|"
BF.buys.item#
CHR(13) CHR(10).
END.
RETURN.
Say we run a beach front business that sells items such as gum, candy, and drinks and also services such as surfing lessons. Patrons purchase only one thing at a time so they often have many sales in a day. The Progress db system keeps track of each beach sale and also constantly updates a current trip table with daily patron totals. A patron comes in 2 months later and says he received bad surfing instructions. The 2 month old sale entry is changed to 1/2 price, which changes his trip data for that day 2 months ago. The system does not include a record change date in the trip table. There is however a record change date in the buys table. I know this is bad bookkeeping, but it illustrates what I'm trying to do.
The SQL code I would use is this:
SELECT Trips.Cust#, Trips.TripDate
FROM Buys INNER JOIN Trips ON
buys.Cust# = Trips.Cust#
AND Buys.BuyDate = Trips.TripDate
GROUP BY Buys.Cust#, Buys.BuyDate,Trips.Cust#, Trips.TripDate, Buys.RecordDate
HAVING Buys.RecordDate between '2007-01-25' and '2007-01-31'
Can anyone help me (please!)?