Need Help with sql code

Copper Contributor
Table1  
codedescription  
A000fever  
A001stomach virus  
    
Table2 
MEMBER_NBRcode1code2 
12368A000NULL 
2476NULLA001 
   

 

 

I need to join these 2 tables. the final result will be in the form of 

Result table
Code1description1code2description2
A000feverNULLnull
NULLnullA001stomach virus
2 Replies

Hi @Trisha_Ravindra 

 

We cannot run a query on the text in your question. What we need is a table with some data. So let's divide the work between us, You will provide what you can and we will fill the blank :) 

 

please post:

1) Queries to CREATE your table(s) including indexes
2) Queries to INSERT sample data.
3) The desired result given the sample, as text or image of excel for example.
4) A short description of the business rules, and how you got 1-2 of the results
5) Which version of SQL Server you are using (this will help to fit the query to your version).

 

Note: This is something you should always provide when you have questions related to queries.

 

Regards,

@Trisha_Ravindra , your table(s) design is a bit strange. Anyway, this should give you the wanted result:

 

SELECT *
FROM Table2 AS T2
     LEFT JOIN
     Table1 AS C1
         ON T2.code1 = C1.code
     LEFT JOIN
     Table1 AS C2
         ON T2.code2 = C2.code