Ok, So currently I am using a pivot which is much more efficient than using multiple joins.
Currently looking like this...
SELECT * FROM
(
SELECT
s.stock_code , sui.field_value, su.field_index
FROM stock_uda as SU
INNER JOIN stock_uda_item as SUI ON SU.field_index = SUI.field_index
INNER JOIN stock as S ON S.stock_id = SUI.stock_id
WHERE sui.field_value != ''
) as A
PIVOT
(
MAX (Field_value)
FOR Field_index in ("846164","846165","846166","848267","945290","945291","1123994","1062208","846169","846170","846171","846172","846173","846174")
) AS MyPivotData
The string of numbers within the IN statement however can change. I can retrieve these by running the following code...
SELECT field_index
FROM stock_uda
I have tried assigning these and creating a string which then I used in my pivot IN statement but haven't had any luck.
Any pointers would be great!