[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[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.3

How to Distribute values from a column in one table to another table based on two other columns

Asked by megnin in SQL Query Syntax, Microsoft Visual Basic.Net, Microsoft Programming

Tags: SQL Server 2000

How could I distribute unique values from Table B to Table A based on values matching in two columns common to both tables?

Here is the Table configuration:
Table A has the following Columns (and Values):
   PrimaryKey (101,     102,   103,        104)
   ForeignKey (NULL,   NULL,  NULL,      NULL)
   Fruit           (Cherry, Apple, Banana,  Okra)
   Color          (Red,     Green, Yellow,   Magenta)

Table B has the following Columns (and Values):
   PrimaryKey (901,       902,    903,      904)
   Fruit            (Cherry,  Apple, Banana, Tomato)
   Color           (Red,      Green, Yellow,   Cyan)

Where the values in the Fruit and Color columns of Table A match the values of the same columns of a record in Table B I want to copy the PrimaryKey of Table B to the ForeignKey of Table A, linking those two records, then continue to check for matches, linking records where it finds a match.

So, when it's done Table A will look like:
   PrimaryKey (101,       102,    103,       104)
   ForeignKey (901,       902,    903,       NULL)
   Fruit            (Cherry,  Apple,  Banana, Okra)
   Color           (Red,      Green, Yellow,    Magenta)

Here's another slightly different example to illustrate what's a match and what's not:

Table A (and Values):
   PrimaryKey (101,      102,     103,       104)
   ForeignKey (NULL,     NULL,  NULL,     NULL)
   Fruit            (Cherry,  Apple, Banana, Okra)
   Color           (Red,      Red,    Red,        Red)

Table B (and Values):
   PrimaryKey  (901,     902,     903,       904)
   Fruit            (Cherry, Apple,  Banana, Tomato)
   Color           (Red,     Green,  Yellow,    Red)

In this example Table A should end up like this:
   PrimaryKey (101,      102,     103,       104)
   ForeignKey (901,       NULL,  NULL,     NULL)
   Fruit            (Cherry,  Apple,  Banana, Okra)
   Color           (Red,       Red,    Red,        Red)

The only ForeignKey copied was where both Cherry and Red matched between the two tables.  Other than that any record from Tablel B can be linked to (match) and record in Table A, exactly once.  Once a fruit from Table B is "used up" it can't be used again.  The ForeignKey values in Table A, copied from Table B, must be unique.

I know it's not simple, so please, no comments consisting only of "This is hard to do."  
If it would be easier to do in VB than using a SQL monster query, that would work for me too. (Don't just tell me "This would be easier in VB." please provide code, I am NOT an experienced programmer, I have to look at an example to craft a Select|Case statement. ;-)

Thank you for having a look.
[+][-]03/10/09 07:37 AM, ID: 23847177Expert Comment

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 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03/10/09 08:15 AM, ID: 23847650Author Comment

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 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03/10/09 08:26 AM, ID: 23847783Accepted Solution

View this solution now by starting your 30-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, Microsoft Visual Basic.Net, Microsoft Programming
Tags: SQL Server 2000
Sign Up Now!
Solution Provided By: udayakumarlm
Participating Experts: 2
Solution Grade: A
 
[+][-]03/10/09 08:27 AM, ID: 23847803Expert Comment

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 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03/10/09 08:28 AM, ID: 23847817Expert Comment

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 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03/10/09 08:30 AM, ID: 23847852Expert Comment

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 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03/10/09 08:34 AM, ID: 23847885Author Comment

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 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03/10/09 08:41 AM, ID: 23847983Expert Comment

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 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03/10/09 08:43 AM, ID: 23848011Expert Comment

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 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03/10/09 08:47 AM, ID: 23848038Author Comment

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 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03/10/09 08:54 AM, ID: 23848117Expert Comment

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 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03/10/09 09:23 AM, ID: 23848503Author Comment

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 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03/10/09 10:40 AM, ID: 23849325Author Comment

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 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03/10/09 03:43 PM, ID: 23852314Expert Comment

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 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03/10/09 03:49 PM, ID: 23852358Author Comment

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 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03/10/09 04:06 PM, ID: 23852497Expert Comment

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 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03/10/09 04:12 PM, ID: 23852546Expert Comment

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 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03/10/09 10:57 PM, ID: 23854212Expert Comment

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 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03/17/09 01:44 PM, ID: 23912762Author Comment

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 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-89 - Hierarchy / EE_QW_3_20080625