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

Special join or other way

$
0
0

Hi Forum,

I am having a problem with incosistent data of two columns with semicolon separated values. Column A and column B should have the exact same number of elements, which is not always the case.

In order to split the values into rows I use the approach from a previous thread
http://social.msdn.microsoft.com/Forums/en-US/06d2a674-c166-49fc-9a70-4fbc383190bb/split-multiple-columns-into-rows-using-xml?forum=transactsql

Joining by the row number I somehow need to normalize the tables that contain the split columns so that both columns are aligned before creating the row number.

If table A has one row and table B has 2, any kind of join would replicate the one row of table A. This gives me a wrong result. What I need is row 1 from table A match row 1 from table B and (non-existing) row 2 from table A with value null match row 2 from table B (vice versa). So:

Table A:
pk      manufacturer
1         man A

Table B:
pk      partnumber
1        part A
1        part B

should result in Table C:
pk      manufacturer   partnumber
1         man A             part A
1         null                 part B

how can I achieve this?

TIA
Alex



Viewing all articles
Browse latest Browse all 23857

Trending Articles



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