Wrox Programmer Forums
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 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 March 11th, 2004, 08:45 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 347
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Adam H-W
Default Query & sub query

Hi there

I've got 2 select statements that I want to put into 1 statement to output a total turnover figure though I'm not sure how to do it.

Here are my queries:

SELECT SUM(t.Price * t.Quantity) AS 'Total Turnover' FROM TransactionLogItem t WHERE t.TransactionID LIKE 'SHHC_%'

SELECT SUM(PP) FROM TransactionLogItem t WHERE t.TransactionID LIKE 'SHHC_%'

and I need to put them together as one

many thanks

Adam
 
Old March 11th, 2004, 09:44 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 839
Thanks: 0
Thanked 1 Time in 1 Post
Default

Maybe I don't understand what you are trying to do, but why not simply:
Code:
SELECT SUM(t.Price * t.Quantity) AS 'Total Turnover', SUM(PP) AS whatever
FROM TransactionLogItem t WHERE t.TransactionID LIKE 'SHHC_%
Jeff Mason
Custom Apps, Inc.
www.custom-apps.com
 
Old March 11th, 2004, 09:51 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 347
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Adam H-W
Default

Hi Jeff,

thanks for your swift response. sorry, I don't think I explained it clearly.

I need the output to be a single total value rather than 2 total values

thanks

Adam
 
Old March 11th, 2004, 02:57 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 839
Thanks: 0
Thanked 1 Time in 1 Post
Default

So your resultset is a single number which is the sum of the two? Try:
Code:
SELECT SUM(t.Price * t.Quantity) + SUM(PP) AS whatever
FROM TransactionLogItem t WHERE t.TransactionID LIKE 'SHHC_%
Jeff Mason
Custom Apps, Inc.
www.custom-apps.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
neeed helpppp query&vb lom2pac Access VBA 3 June 2nd, 2006 03:55 PM
Run query & Exporting the Data to Excle anukagni Access 2 January 21st, 2006 04:49 AM
Query database for List of tables & other details imsuneeta SQL Server 2000 2 January 18th, 2005 07:48 AM
Append & Delete Query Teqlump Access 2 October 7th, 2004 03:40 AM
Error on Make-Table Query In Union Query rylemer Access 1 August 20th, 2003 07:42 PM





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