Advertisement

06.17.2008 at 02:09PM PDT, ID: 23493302
[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

T-SQL syntax to create aging columns for order data

Asked by larrybye in SQL Query Syntax, SQL Server 2005

I need help creating columns for the number of days since an order has been place, I cannot figure out how to code the query for the number of days since the order has been place. Ex: I have 37 total orders for a customer that have not shipped, 1 order is 0-1 day old and the rest are +5 days. I need my query to return results like the below example:

bill_to_code    bill_to_name                   0-1 day 2 day 3 day 4 day +5 day TotalOrder
--------------- ------------------------------ ------- ----- ----- ----- ------ -----------
100115          INGRAM MICRO CONSIGNED         1       0     0     0     36     37



Below is my query and the data it returns:

SELECT t_ord.bill_to_code,
t_ord.bill_to_name,
COUNT(DISTINCT t_ord.order_number) AS [TotalOrder],
CONVERT(nvarchar(10),t_ord.order_date,112) AS [OrderDate]
FROM t_order_detail tod
INNER JOIN t_order t_ord ON tod.order_id = t_ord.order_id
INNER JOIN t_item_master tim ON tod.item_master_id = tim.item_master_id
WHERE  t_ord.type_id <=5 AND
t_ord.status NOT IN ('S','X')
AND t_ord.bill_to_code = '100115'
GROUP BY t_ord.bill_to_code, t_ord.bill_to_name , CONVERT(nvarchar(10),t_ord.order_date,112)
ORDER BY bill_to_code


bill_to_code    bill_to_name                   TotalOrder  OrderDate
--------------- ------------------------------ ----------- ----------
100115          INGRAM MICRO CONSIGNED         5           20080516
100115          INGRAM MICRO CONSIGNED         2           20080520
100115          INGRAM MICRO CONSIGNED         1           20080604
100115          INGRAM MICRO CONSIGNED         28          20080605
100115          INGRAM MICRO CONSIGNED         1           20080617

Im sure it is some nested query or union to get the result I want but I just cannot get the syntax correct.

Thank you,
Larry ByeStart Free Trial
[+][-]06.17.2008 at 02:14PM PDT, ID: 21807550

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.

 
[+][-]06.17.2008 at 05:47PM PDT, ID: 21808821

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, SQL Server 2005
Sign Up Now!
Solution Provided By: mark_wills
Participating Experts: 2
Solution Grade: B
 
 
[+][-]06.18.2008 at 06:00AM PDT, ID: 21812308

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.

 
[+][-]06.18.2008 at 09:18AM PDT, ID: 21814475

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.

 
[+][-]06.18.2008 at 09:26AM PDT, ID: 21814544

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.

 
[+][-]06.19.2008 at 05:22AM PDT, ID: 21821403

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.

 
[+][-]06.19.2008 at 07:29AM PDT, ID: 21822444

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