Advertisement

07.30.2008 at 07:32AM PDT, ID: 23607476
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.3

SQL Select within select line

Asked by ratkinso666 in SQL Query Syntax, MS SQL DTS, SQLBase

Tags: ,

Hi all, how can I do this so that I get the totals for EACH individual customer, everything works fine in this query, BUT it gives me the total for ALL customers.  What can I do to make it so that I could use the customer number from the first part of my statement to be fed into the second part or something like that.  Normally I would just make this two statements but wanted to make it one if possible.

Thanks,
Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
Declare @StartDate datetime	
Declare @StopDate datetime	
 
Set @StartDate = DateAdd(year,0,GetDate())
Set @StartDate =  '01/01/' + cast(Year(@StartDate) as varchar(4))
 
Set @StopDate = GetDate()
Set @StopDate = Cast(Month(@StopDate) as varchar(2)) + '/01/' + cast(Year(@StopDate) as varchar(4))
 
 
SELECT     rpt_AllianceRevenue.CN_Description AS Customer, rpt_AllianceRevenue.AC_CustomerNo AS [Customer No], SUM(rpt_AllianceRevenue.SumOfRevenue)
                       AS Revenue, 
                      (Select Sum(Rl_NetExtension) 
		       From hcisdata..ARLine 
                            inner join hcisdata..ARheader on hcisdata..ARHeader.Rh_ID = hcisdata..ARLine.Rl_ARHeaderID
                            inner join rpt_AllianceRevenue on AC_CustomerNo = Rh_CustomerNoWork
                       WHERE     (rpt_AllianceRevenue.[Date] >= @StartDate) AND (rpt_AllianceRevenue.[Date] <= @StopDate)
                       ) AS Total_Rev, YEAR(rpt_AllianceRevenue.[Date]) AS Year, 
                      HCISData..Customer.Cu_City + ', ' + HCISData..Customer.Cu_State AS Site, HCISData..Customer.Cu_City, 
                      HCISData..Customer.Cu_State
FROM         rpt_AllianceRevenue INNER JOIN
                      HCISData..Customer ON rpt_AllianceRevenue.AC_CustomerNo = HCISData..Customer.Cu_CustomerNo
WHERE     (rpt_AllianceRevenue.[Date] >= @StartDate) AND (rpt_AllianceRevenue.[Date] <= @StopDate)
GROUP BY rpt_AllianceRevenue.CN_Description, rpt_AllianceRevenue.AC_CustomerNo, HCISData..Customer.Cu_City, HCISData..Customer.Cu_State, 
                      YEAR(rpt_AllianceRevenue.[Date])
ORDER BY rpt_AllianceRevenue.CN_Description
[+][-]07.30.2008 at 07:35AM PDT, ID: 22120807

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.30.2008 at 07:48AM PDT, ID: 22120949

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.30.2008 at 07:51AM PDT, ID: 22120987

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: SQL Query Syntax, MS SQL DTS, SQLBase
Tags: microsoft, sql enterprise manager
Sign Up Now!
Solution Provided By: chapmandew
Participating Experts: 1
Solution Grade: A
 
 
[+][-]07.30.2008 at 07:51AM PDT, ID: 22120994

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.30.2008 at 07:54AM PDT, ID: 22121022

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.30.2008 at 07:56AM PDT, ID: 22121037

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628