Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL Help needed

Status
Not open for further replies.

PeteAmsterdam

Programmer
Jun 3, 2005
76
US
I need some serious sql help. I have a program that goes through our line item sales data and produces a report on a customer by customer basis detailing the summary data for the line items, IE: total sales, total cost,
margins, etc. However, in meeting with the sales staff last week, they want to know when each item was last purchased. Frankly I have no idea
whatsoever of how to include that in the statement.

Here is what I have right now:


DECLARE DETAILCURSOR CURSOR
FOR SELECT
ILNINV#A,
ILNSOLDTO,
ICMNAME,
ILNSTK,
ILNDESC,
SUM(ILNEPRICE),
SUM(ILNEUAVCST),
SUM(ILNEPRICE) - SUM(ILNEUAVCST) AS MARGIN
FROM INVMARGIN
WHERE
ILNINV#A = :ALPHPARM AND
ILNINVDATE >= :SDATE AND ILNINVDATE <= :EDATE
GROUP BY
ILNINV#A,
ILNSOLDTO,
ICMNAME,
ILNSTK,
ILNDESC
ORDER BY
ILNINV#A,
ILNSOLDTO,
MARGIN DESC


There is a field included in the file called ILNINVDATe which is the sale date, but I am only using that field thus far for record selection....any
ideas or suggestions would be appreciated.
 
I would tend to believe that inlinvdate might be the one.. if so.

Code:
 FOR SELECT                                    
        ILNINV#A,                                 
       ILNSOLDTO,                                
        ICMNAME,                                  
        ILNSTK,                                   
        ILNDESC,
[blue]        ILNINVDATE,[/blue]                                  
        SUM(ILNEPRICE),                           
        SUM(ILNEUAVCST),                          
        SUM(ILNEPRICE) - SUM(ILNEUAVCST) AS MARGIN
    FROM INVMARGIN                                
    WHERE                                         
        ILNINV#A = :ALPHPARM AND                     
        ILNINVDATE >= :SDATE AND ILNINVDATE <= :EDATE
    GROUP BY                                         
        ILNINV#A,                                    
        [blue]ILNIVDATE,[/blue]
        ILNSOLDTO,                                   
        ICMNAME,                                     
        ILNSTK,                                      
        ILNDESC                                      
    ORDER BY                                         
        ILNINV#A,  
        ILNSOLDTO, 
        MARGIN DESC
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top