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 |
|
massimoo
Starting Member
2 Posts |
Posted - 2013-01-02 : 04:49:01
|
| Hi all,I'm pretty new to SQL and I would need some help with following issue:I have two tables:SalesOrderHeaderSalesOrderLinesIn the SalesOrderLines I have Quantity and PriceI would like to create a query that gets the SalesOrderId and calculates the total (qnt*price). SalesOrderId is the key.SELECT a.SalesOrderId, a.Customer, (TOTAL HERE SOMEHOW :)FROM SalesOrderHeader a, SalesOrderLines bWHERE a.SalesOrderId = b.SalesOrderId and a.SalesOrderDate>=20130101Thanks for the help : ) |
|
|
vijays3
Constraint Violating Yak Guru
354 Posts |
Posted - 2013-01-02 : 05:06:43
|
| [code]Try this ..SELECTa.SalesOrderId, a.Customer, sum(b.Quantity *b.Price)FROMSalesOrderHeader a, SalesOrderLines bWHEREa.SalesOrderId = b.SalesOrderId anda.SalesOrderDate>=20130101group by a.SalesOrderId, a.Customer[/code]Vijay is here to learn something from you guys. |
 |
|
|
massimoo
Starting Member
2 Posts |
Posted - 2013-01-02 : 05:58:31
|
| Thanks a lot, worked like a charm! |
 |
|
|
vijays3
Constraint Violating Yak Guru
354 Posts |
Posted - 2013-01-02 : 06:50:37
|
| you are welcome..Vijay is here to learn something from you guys. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2013-01-03 : 06:29:19
|
| If SalesOrderDate is of Datetime datatype, you need to use date values within single quotesa.SalesOrderDate>='20130101'MadhivananFailing to plan is Planning to fail |
 |
|
|
Jeff Moden
Aged Yak Warrior
652 Posts |
Posted - 2013-01-09 : 19:21:59
|
quote: Originally posted by massimoo Thanks a lot, worked like a charm!
The next question would be, "Do you understand how it works?"--Jeff Moden RBAR is pronounced "ree-bar" and is a "Modenism" for "Row By Agonizing Row".First step towards the paradigm shift of writing Set Based code:"Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column." When writing schedules, keep the following in mind:"If you want it real bad, that's the way you'll likely get it." |
 |
|
|
|
|
|
|
|