Pivot rows to columns
SELECT
[Pivot_Table].Column_Name_1
, [Pivot_Table].Column_Name_2
, [Pivot_Table].cell_1
, [Pivot_Table].cell_2
, [Pivot_Table].cell_3
...
FROM (
SELECT
[Table_One].Column_Name_1
, [Table_One].Column_Name_2
, [Table_Two].Pivot_Column
, [Table_Two].Values_Column
FROM [database].[dbo].[table_one] AS [Table_One]
LEFT JOIN [database].[dbo].[table_two] AS [Table_Two] ON [Table_One].Primary_Key = [Table_Two].Primary_Key
) AS [Data_Table]
PIVOT (
MAX (Values_Column)
FOR Pivot_Column IN (
/* These items pivot to column names */
[cell_1]
, [cell_2]
, [cell_3]
, ...
)
) AS [Pivot_Table]