Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
jwells
Starting Member
17 Posts |
Posted - 2013-06-03 : 17:06:38
|
I'm trying to write a statement that calculates pricing for an invoice. It sums all the labor transactions as labor, sums the parts transactions as parts, and other transactions as other. Then it takes the difference of the total summed pricing and the bid price. Adds or subtracts the difference from the total labor so that the invoice will match the bid price. Looks something like:Select sum(labor transactions) as labor, sum(parts transactions) as parts, sum(other transactions) as other, (labor + bidprice - (parts + labor + other) as BidIs it possible to sum transactions then perform a calculation on those sums? |
|
MuMu88
Aged Yak Warrior
549 Posts |
Posted - 2013-06-03 : 17:48:31
|
Try this:[CODE]Select (labor + bidprice - (parts + labor + other)) as Bid FROM( ( SELECT sum(labor transactions) FROM TABLE) as labor, ( SELECT sum(parts transactions) FROM TABLE) as parts, ( SELECT sum(other transactions) FROM TABLE) as other, bidprice FROM TABLE) A[/CODE] |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-06-03 : 23:44:07
|
one question. Is Bidprice also in same table? when you aggregate data from table, dont you also want to aggregate bidprice? is it already at item level or at aggregated level in table?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
 |
|
|
|
|