Posted by Erland Sommarskog on 03/09/06 01:06
Laphan (info@SpamMeNot.co.uk) writes:
> This works in a fashion, but I need to sort of query the stocktransactions
> table again to get the sum of the st.QUANTITY table for
> st.TRANSACTIONTYPE=1
> so that I can have an extra select field of Sum(st.QUANTITY) AS 'Qty
> Ordered', ie transactions with transactiontype of 1 are sales orders and
> type 8 are invoices.
It sounds like you could just add one column to your SELECT list:
SUM(CASE st.TRANSACTIONTYPE WHEN 1 THEN st.QUANTITY ELSE 0 END)
AS "Qty Ordered"
By the way, use of single quotes to delimit column aliases is deprected
in SQL 2005.
--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
[Back to original message]
|