Advertisement

07.28.2006 at 04:18PM PDT, ID: 21936052
[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!

8.4

Need Help With a join query, containing a sum function.

Asked by apuma in MS SQL Server

Tags: , , ,

Hello Experts.
     Im Caught up on a query.

I need to retrieve sales order information pulling from two tables, along with the cost of unshipped items pulling from a 3rd table.

Example:

tblSalesOrder
SalesOrderID  UserID   SalesPersonID  OrderStatusID  
1                   25           11503             1
2                   12           11503             1
5                   25           11503             2
3                   12           11306             3

tblUserInfo
UserID           FirstName   LastName     Company
12                Jane            Smith           Microsoft
25                Jon              Doe             Acme
11503           Sales           Person         MyCompany
11306           Other          Sales            MyCompany

tblSalesOrdrItems
SalesOrderID  Quantity   BOQuantity  AppliedPrice
1                   1             0                 100
1                   2             2                  75
1                   1             1                  20
2                   2             2                  500
3                   1             0                  99

Rough Draft of Query
Select
'Sales Order #' + convert(varchar(4), a.SalesOrderID ) as Type , b.FirstName + ' ' + b.LastName as 'Name' , b.Company , a.DateCreated as 'Date' , sum(c.BOQuantity * c.AppliedPrice) as total
from
tblSalesOrder a, tblUserInfo b  
inner join tblsalesorderitems c
on c.salesorderid = a.salesorderid
where a.userid = b.userid AND a.SalesPersonID = 11503 and a.datecreated >= '2006-07-01 00:00:00' AND a.datecreated <= '2006-07-28 23:59:59' And a.orderstatusid = 1  Order By 'Date' Desc

Current Error:
"The column prefix 'a' does not match with a table name or alias name used in the query."

Desired Relults:
Type                 Name          Company  Date      Total
Sales Order#1   Jon Doe       Acme       ####     170
Sales Order#2   Jane Smith   Microsoft  ####   1000



I have tried a few different ways to write this with no success.  the hard part for me is that the "sum" part of the select requires its own where clause.

I have also tried a "group by" with similar faliure.

I would prefer not to write this as a stored procedure as it is only used in 1 place in the program.
i also want to stay away from multiple queries, as that would be slow.

Please help.
Thx in advance
Anthony
Start Free Trial
 
 
[+][-]07.28.2006 at 04:28PM PDT, ID: 17205383

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.28.2006 at 04:32PM PDT, ID: 17205397

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.28.2006 at 04:37PM PDT, ID: 17205429

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.28.2006 at 04:40PM PDT, ID: 17205443

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.28.2006 at 04:41PM PDT, ID: 17205452

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.28.2006 at 04:42PM PDT, ID: 17205462

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.28.2006 at 04:46PM PDT, ID: 17205484

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.28.2006 at 04:52PM PDT, ID: 17205500

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

Zone: MS SQL Server
Tags: join, function, query, sum
Sign Up Now!
Solution Provided By: DireOrbAnt
Participating Experts: 2
Solution Grade: A
 
 
[+][-]07.28.2006 at 04:59PM PDT, ID: 17205513

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.

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