Wrox Home  
Search P2P Archive for: Go

  Return to Index  

sql_language thread: For the gurus


Message #1 by "Arbon Reimer" <arbon_reimer@h...> on Thu, 16 Aug 2001 13:50:31 -0600
SELECT
    VendorName, SUM(EO_Total)
FROM
    Vendors
INNER JOIN
    EOs
ON
    Vendors.VendorID = EO.VendorID
WHERE
    EO.Date BETWEEN (...)
GROUP BY
    Vendors.VendorID


should give you a starting block...
Sorry that I don't have time to work out your table structure from your
sproc, but perhaps if you told us what's wrong with what Brian suggested...

That said, you definately don't need a cursor to do this (as far as I can
tell), all you need to to get the appropriate set of results...

Cheers
Ken

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
----- Original Message -----
From: "Arbon Reimer" <arbon_reimer@h...>
To: "sql language" <sql_language@p...>
Sent: Friday, August 17, 2001 9:29 PM
Subject: [sql_language] RE: For the gurus


: That works, but the solution I need is much more complex.  I can get the
: numbers I need for only one Vendor, but not for all the vendors.  I tried
: a cursor and it returned too much information...
:
: What I need to do is for each Vendor in my vendors table, retrieve a total
: of the amounts of money we spent in Purchase Orders (PO_HEADER) and
: Efficiency Orders (EOs) between certain dates.  Each Purchase Order or
: Efficiency Order has a Vendor number associated with it.
:
: Here's what worked before:
: CREATE PROCEDURE procVendorYTDTotals
: (@VendorNumber char(4), @date1 char(10), @date2 char(10))
: AS
:
: DECLARE @eototal money
: DECLARE @pototal money
: --fetch first total
: SELECT @eototal=SUM(EO_AMOUNT)
: FROM EOs
: WHERE VENDOR_NUMBER = @VendorNumber
: AND EO_DATE BETWEEN CAST(@date1 as datetime) AND CAST(@date2 as datetime)
: --fetch second total
: SELECT @pototal=SUM(PO_TOTAL)
: FROM PO_HEADER
: WHERE VENDOR_NUMBER = @VendorNumber
: AND PO_DATE BETWEEN CAST(@date1 as datetime) AND CAST(@date2 as datetime)
: --do computation, fetch vendor name for display
: SELECT VENDOR_NUMBER, VENDOR_NAME, @eototal AS EOTOTAL, @pototal as
: POTOTAL, SUM(@eototal + @pototal) AS YTD_TOTAL
: FROM VENDORS
: WHERE VENDOR_NUMBER = @VendorNumber
: GROUP BY VENDOR_NUMBER, VENDOR_NAME
: --end SQL statements here
:
: I'm having a difficult time getting it to work for ALL vendors.  Any
: suggestions are sincerely appreciated.  Thanks in advance!
: Regards,
: Arbon Reimer



  Return to Index