I have several tables all holding small amounts of data on a batch of product. For example, I have a table (called 'Tests') that holds a test number, a test name and the description. This is referenced by my batch table, which holds a test number, test result (as a real) and the batch number itself.
Some batches may have 50 tests, some may have 30, some may have as little as 1.
I was hoping to create a view that converts something like these tables;
BatchNumber TestNum TestResult | TestNumber TestName TestDesc
----------- -------- ----------- | ----------- --------- ---------
1000 1 1.20 | 1 Thickness How thick the product is
1001 1 1.30 | 2 Colour What colour the product is
1001 2 45.1 | 3 Weight How heavy the product is
...
to the following;
BatchNumber Thickness Colour Weight
------------ --------- ------ -------
1000 1.20 NULL NULL
1001 1.30 45.1 NULL
...
Though the 'null' could just be blank, it would probably be better that way, I just used that to better show my requirement.
I've found many articles online on the benefit of PIVOTing, UNPIVOTing, UNIONing but none show the direct benefit, or indeed provide a clear and succinct way of using the data without copying data into a new table, which isn't really useful for my need. I was hoping that a view would be possible so that end-user applications can just call that instead of doing the joins locally.
I hope that makes sense, and thank you!