Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Intersecting values of Two Tables

$
0
0

I have two tables, each with 40 columns.

Row Id is what I want to join on.

Table A contains Customer Information

Table B Contains Metric information for that customer.

For each Customer I only want revtrieve data in a specific column from Table A if there is either a 2 or a 7 in the corresponding intersection of Table B based upon RowId and ColumnName. The ColumnNames are the same in both tables.

Table A

RowId	Column1	        Column2	        Column3	     Column4
1	ABC Enterprises	Reynolds	Lose	     Right
2	Phoenix	        Davis	        Win	     Left
3	Wash DC	        Casey	        Even	     Right

Table B

RowId Column1 Column2 Column3 Column4 1 ABC Enterprises 2 48 7

2 Phoenix 54 55 59 3 Wash DC 41 2 2


Result Set

RowId	Column1	        Column2	        Column3	     Column4
1	ABC Enterprises	Reynolds	NULL	     Right
3	Wash DC	        NULL	        Even	     Right

The Result set does not include Row Id 2 because there were no 7s or 2s

Row 1 in the Result Set Has a Null for Column3 since there was no 7 or 2

Row 3 has a null for Column2 since there was no 7 or 2.

Trying to see how best to approach this - seems like a cube question, or a multi-dimensional query.


John



Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>