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 |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2003-01-23 : 08:50:45
|
| Carlos writes "Hi,I'm new to sql server and I would like to know if you guys can help me out. I'm using sql server 2000 on a Windows 2000 server.I have two tables with the following fieldsOrder_detail Table Customer_numberorder_numberStart_dateCompany_nameContract_amountBase_Info TableCustomer_NumberBase_InfoThe query that I need is to get the sum of the contract_amount for thecustomers from Base_Info table that exits in Order_detailand have orders where start_date <= '01/02/02'. At the same time sum the contract_amount for the same customers, but that were placed after start_date '01/02/02'Is this possible in one select statement?Thank you in advance..." |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2003-01-23 : 10:32:01
|
| SELECT Customer_number, Base_Info SUM(CASE WHEN Start_Date <= '01/02/02' THEN Contract_Amount ELSE 0 END) as TotalBefore, SUM(CASE WHEN Start_Date > '01/02/02' THEN Contract_Amount ELSE 0 END) as TotalAfterFROM Order_DetailINNER JOIN Base_InfoON Order_Detail.Customer_Number = Base_Info.Customer_NumberGROUP BY Customer_Number, Base_Info- JeffEdited by - jsmith8858 on 01/23/2003 10:32:41 |
 |
|
|
|
|
|