Advertisement

09.23.2008 at 10:08AM PDT, ID: 23755711
[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.1

Joining two tables that could have more items for each idea on either side of tables

Asked by johnnie240 in SQL Query Syntax, SQLBase

Tags:

I need to join two tables with similar data but don't uniformly line up.  Here is a sample

Pay Table:
ID      PayIndex      PayDate            Payment      PayRate
1      0      2002-10-17 00:00:00.000      574028.7      0.0339
1      1      2003-02-18 00:00:00.000      875637      0.0339
1      2      2003-08-15 00:00:00.000      875637      0.0339
1      3      2004-02-17 00:00:00.000      875637      0.0339
...
1      11      2008-02-15 00:00:00.000      754020.75      0.0339


Rec Table:
ID      RecIndex      RecDate            Reciept      RecRate
1      0      2002-10-17 00:00:00.000      30952.6809374938      0.0143798749999971
1      1      2002-11-01 00:00:00.000      63968.8739374873      0.0143798749999971
1      2      2002-12-02 00:00:00.000      63968.8739374873      0.0143798749999971
...
1      11      2003-09-02 00:00:00.000      59841.8498124881      0.0143798749999971
...
1      70      2008-08-01 00:00:00.000      54955.8878402668      0.0143798749999971

Here is a sample of the result I want:
ID      SortIndex      Payment      RecRate      RecDate      Reciept      RecRate
1      0      -574028.7      0.0339      2002-10-17       30952.6809374938      0.0143798749999971      2002-10-17
1      1      -875637      0.0339      2003-02-18       63968.8739374873      0.0143798749999971      2002-11-01
1      2      -875637      0.0339      2003-08-15       63968.8739374873      0.0143798749999971      2002-12-02
...
1      10      -754020.75      0.0339      2007-08-15       66032.3859999868      0.0143798749999971      2003-08-01
1      11      -754020.75      0.0339      2008-02-15       59841.8498124881      0.0143798749999971      2003-09-02
1      12      NULL      NULL      NULL      68095.8980624864      0.0143798749999971      2003-10-01       NULL
1      13      NULL      NULL      NULL      57778.3377499885      0.0143798749999971      2003-11-03       NULL
...
1      69      NULL      NULL      NULL      55084.3081128363      0.0143798749999971      2008-07-01       NULL
1      70      NULL      NULL      NULL      54955.8878402668      0.0143798749999971      2008-08-01       NULL

I am currently able to get this result for one ID but not for the whole table with the folloiwing query:

SELECT  Rec.SwpID, Rec.RecIndex AS SortIndex, Pay.Payment * -1 As Payment, Pay.PayRate, Pay.PayDate, Rec.Reciept, Rec.RecRate, Rec.RecDate
FROM         [#SwpPay]  as Pay Full Outer JOIN
                      [#SwpRec] as Rec ON Pay.SwpID = Rec.SwpID
                     AND Rec.RecIndex = Pay.PayIndex
where Rec.SwpID = 2251 OR Pay.SwpID = 2251
Order by Rec.SwpID, Rec.RecIndex


How do I write the query for all ID's?

An additional note is that the Pay or Rec could have more items and even the same number.Start Free Trial
[+][-]09.23.2008 at 10:14AM PDT, ID: 22551723

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.

 
[+][-]09.23.2008 at 10:27AM PDT, ID: 22551849

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.

 
[+][-]09.23.2008 at 11:04AM PDT, ID: 22552209

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.

 
[+][-]09.23.2008 at 11:07AM PDT, ID: 22552241

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, SQLBase
Tags: SQL
Sign Up Now!
Solution Provided By: DanielWilson
Participating Experts: 2
Solution Grade: A
 
 
[+][-]09.23.2008 at 11:12AM PDT, ID: 22552279

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 / EE_QW_2_20070628