Advertisement

04.29.2008 at 12:05PM PDT, ID: 23363209
[x]
Attachment Details

Combine SQL Statements

[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!

6.4
Tags:

Microsoft, SQL Server, 2000

I have query #1 that returns one column of dates.  And I have query #2 which returns 3 columns - item, date, and Qty.  That query #2 returns those values for some dates and not for others.  I need to combine the queries so that my new combined query will return every item in #2, and for every item will return a row for EVERY date in Q#1 and the value returned will be the value for that date from Query #2, and if there is no value in Query #2 for that particular date, then the value returned would be the same value as the previous day in Query #1 (which may not always be the previous calendar day - as it excludes weekends).

See attached SQL and sample data in the attached XLS file
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
Query #1:
 
SELECT     TOP 100 PERCENT DateFull
FROM         dbo.tsi_view_DateLookup
WHERE     (DateFull BETWEEN CONVERT(DATETIME, '2007-01-01 00:00:00', 102) AND CONVERT(DATETIME, '2008-12-31 00:00:00', 102)) AND 
                      (NOT (WeekDayName LIKE 'S%'))
ORDER BY DateFull
 
 
Query #2:
 
SELECT DISTINCT 
                      TOP 100 PERCENT item_id, CAST(CONVERT(varchar(10), trans_date, 101) AS datetime) AS [Date], quantity + on_hand_before_trans AS QtyOnHand
FROM         dbo.p21_view_inv_tran
WHERE     (trans_date IN
                          (SELECT     MAX(trans_date)
                            FROM          dbo.p21_view_inv_tran
                            GROUP BY item_id, CAST(CONVERT(varchar(10), trans_date, 101) AS datetime)))
ORDER BY item_id, CAST(CONVERT(varchar(10), trans_date, 101) AS datetime)
Attachments:
 
Sample Data
 
 
Expert Comment by Dan7el:

All comments and solutions are available to Premium Service Members only. Start your 7-day free trial to view the solution to this question.

Already a member? Login to view this solution.

 
 
Author Comment by timoteoga:

All comments and solutions are available to Premium Service Members only. Start your 7-day free trial to view the solution to this question.

Already a member? Login to view this solution.

 
 
Expert Comment by bcaff86:

All comments and solutions are available to Premium Service Members only. Start your 7-day free trial to view the solution to this question.

Already a member? Login to view this solution.

 
 
Expert Comment by bcaff86:

All comments and solutions are available to Premium Service Members only. Start your 7-day free trial to view the solution to this question.

Already a member? Login to view this solution.

 
 
Expert Comment by Dan7el:

All comments and solutions are available to Premium Service Members only. Start your 7-day free trial to view the solution to this question.

Already a member? Login to view this solution.

 
 
Author Comment by timoteoga:

All comments and solutions are available to Premium Service Members only. Start your 7-day free trial to view the solution to this question.

Already a member? Login to view this solution.

 
 
Author Comment by timoteoga:

All comments and solutions are available to Premium Service Members only. Start your 7-day free trial to view the solution to this question.

Already a member? Login to view this solution.

 
 
Expert Comment by bcaff86:

All comments and solutions are available to Premium Service Members only. Start your 7-day free trial to view the solution to this question.

Already a member? Login to view this solution.

 
 
Author Comment by timoteoga:

All comments and solutions are available to Premium Service Members only. Start your 7-day free trial to view the solution to this question.

Already a member? Login to view this solution.

 
 
Expert Comment by bcaff86:

All comments and solutions are available to Premium Service Members only. Start your 7-day free trial to view the solution to this question.

Already a member? Login to view this solution.

 
 
Author Comment by timoteoga:

All comments and solutions are available to Premium Service Members only. Start your 7-day free trial to view the solution to this question.

Already a member? Login to view this solution.

 
 
Accepted Solution by bcaff86:

All comments and solutions are available to Premium Service Members only. Start your 7-day free trial to view the solution to this question.

Already a member? Login to view this solution.

 
 
Author Comment by timoteoga:

All comments and solutions are available to Premium Service Members only. Start your 7-day free trial to view the solution to this question.

Already a member? Login to view this solution.

 
 
Administrative Comment by cs97jjm3:

All comments and solutions are available to Premium Service Members only. Start your 7-day free trial to view the solution to this question.

Already a member? Login to view this solution.

 
 
Administrative Comment by Computer101:

All comments and solutions are available to Premium Service Members only. Start your 7-day free trial to view the solution to this question.

Already a member? Login to view this solution.

 
 
20081119-EE-VQP-45 / EE_QW_2_20070628