Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > SQL Language
|
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 8th, 2005, 12:16 PM
Authorized User
 
Join Date: Oct 2004
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to cuzintone Send a message via Yahoo to cuzintone
Default Placing a computed sum in a table field

If I used this query, it returns a separate recordset that contains the sum of all the invoices, how can I put the sum into a field in an existing table?


declare @daytolook datetime
select @daytolook = convert(datetime, '5-1-2005', 102)


                SELECT distinct dbo.suppliers.supplierid,
              dbo.invoices.InvoiceID, dbo.invoices.DueDate,
              dbo.invoices.AmountToPay,invoicedetail.Quantity * invoicedetail.Unitprice as linetotal , dbo.invoices.Paid
          FROM dbo.invoices INNER JOIN
                      dbo.invoicedetail ON dbo.invoices.InvoiceID = dbo.invoicedetail.InvoiceID INNER JOIN
                      dbo.LineItems ON dbo.invoicedetail.LineItemID = dbo.LineItems.LineItemID INNER JOIN
                      dbo.suppliers ON dbo.invoices.SupplierID = dbo.suppliers.SupplierID
              WHERE (dbo.invoices.DueDate <= @daytolook) and (dbo.invoices.Paid = 0)
        group by dbo.suppliers.supplierid,
              dbo.invoices.InvoiceID, dbo.invoices.DueDate,
              dbo.invoices.AmountToPay,invoicedetail.Quantity, invoicedetail.Unitprice ,invoicedetail.Quantity * invoicedetail.Unitprice, dbo.invoices.Paid
        order by dbo.suppliers.supplierid,
              dbo.invoices.InvoiceID, dbo.invoices.DueDate,
              dbo.invoices.AmountToPay,invoicedetail.Quantity * invoicedetail.Unitprice , dbo.invoices.Paid
        compute sum (invoicedetail.quantity * invoicedetail.unitprice) by dbo.suppliers.supplierid,
              dbo.invoices.InvoiceID, dbo.invoices.DueDate




__________________
---------------------------
\"I finally understand the true value of time, for it is the bonds between us that give time its meaning.\"
 
Old April 15th, 2005, 05:02 AM
Registered User
 
Join Date: Nov 2003
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

How about putting the results of this query into temp table, then joining that temp table to whatever is necessary to move that sum column where you want?

Stoney





Similar Threads
Thread Thread Starter Forum Replies Last Post
Placing Table in a Header or Footer sunny227 XSLT 13 March 12th, 2008 02:41 AM
Placing a Primary Key in Another Table When Adding DavidWE Access VBA 1 August 10th, 2006 12:46 PM
How to get Cumulative Sum of a Field badsy Crystal Reports 1 January 20th, 2006 05:09 PM
Urgent. Placing table on top of drop down tanusree_ghosh CSS Cascading Style Sheets 2 January 4th, 2005 02:05 PM
Update parent table with the sum of child table gbrown SQL Language 2 November 9th, 2004 07:53 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.