Hi All
Not even sure how to describe my issue as I am no expert in SQL at all. In short I have three tables
Table 1 - Dataset that has the following columns
Dataset_Family_Code
DIM1
DIM2 etc up to DIM 20 (The dim columns contain the DIM_Code value from a table called DIM_Codelist)
Table 2 - DIM_Codelist_Table
Dim_Codelist (This column contains the names of multiple datasets that can have multiple values in the DIM_Code column - For example - This column might have the value Frequency and then in DIM_Code you could have A, M , W and in DIM Code_Description the values would be Annual, Monthly and Weekly)
Dim_Code
Dim_Code_Description
Table 3 - Dataset_Dimensions
Dataset_Family Code (This column is the link between this table and the Dataset table listed first
DIM1 to DIM 20 the values in these columns are the DIM_Codelist values from table listed second.
So in short I have the dataset table that has a Dataset_Family_Codes and DIM_Codes for each Dimension from 1 to 20
What I need to do is to link the DIM_Code back to the DIM_Codelist_Table but first obtain the DIM_Codelist for each dimension as the same value occurs multiple times in the DIM_Code column so I need to know which DIM_Codelist applies to each DIM_Value of each Dataset_Family_Code and return me all the values in new columns called DIM_Code_Description1 to 20.
Unfortunately I am only able to do one join and then I am stuck!
SELECT ecbd.[Id]
,ecbd.[Dataset_Code]
,ecbd.[Description]
,ecbd.[Extract]
,ecbd.[Classification]
,ecbd.[Dataset_Family_Code] as ECB_Datasets_Family_Code
,ecbd.[DIM1] DIMENSION1_FROM_ECB_Datasets
,ecbdd.Dataset_Family_Code
,ecbdd.[DIM1] as DIMENSION_TABLE
,ecbdc.DIM_Codelist
,ecbdc.DIM_Code
,ecbdc.DIM_Code_Description
--,ecbd.[DIM2]
--,ecbd.[DIM3]
--,ecbd.[DIM4]
--,ecbd.[DIM5]
--,ecbd.[DIM6]
--,ecbd.[DIM7]
--,ecbd.[DIM8]
--,ecbd.[DIM9]
--,ecbd.[DIM10]
--,ecbd.[DIM11]
--,ecbd.[DIM12]
--,ecbd.[DIM13]
--,ecbd.[DIM14]
--,ecbd.[DIM15]
--,ecbd.[DIM16]
--,ecbd.[DIM17]
FROM [dbo].[DIM_ECB_Datasets] ecbd
inner join [dbo].DIM_ECB_Datasets_Dimensions ecbdd on ecbdd.Dataset_family_code = ecbd.Dataset_Family_Code
inner join [dbo].DIM_ECB_Dataset_Dimension_Codelist ecbdc on ecbdc.DIM_Codelist = ecbdd.DIM1 where ecbd.[DIM1] = ecbdc.DIM_Code