Skip to content

Instantly share code, notes, and snippets.

@sotirisf
Created January 12, 2018 22:57
Show Gist options
  • Save sotirisf/29cb9ccbb8289d7a38d4da989fc2f490 to your computer and use it in GitHub Desktop.
Save sotirisf/29cb9ccbb8289d7a38d4da989fc2f490 to your computer and use it in GitHub Desktop.
Get Umbraco dictionary entries for all languages in a pivoted table (each language with its own column)
DECLARE @DynamicColumns NVARCHAR(MAX);
DECLARE @DynamicSQL NVARCHAR(MAX);
SELECT @DynamicColumns = COALESCE(@DynamicColumns+', ', '')+QUOTENAME(languageISOCode)
FROM
(
SELECT DISTINCT
languageISOCode
FROM umbracolanguage
) AS FieldList;
SET @DynamicSQL =
'SELECT [key], ' + @DynamicColumns
+ ' FROM'
+ ' ('
+ 'SELECT l.languageISOCode, d.[key], t.[value]'
+ ' FROM cmsDictionary d'
+ ' INNER JOIN cmsLanguageText t ON d.id = t.UniqueId'
+ ' INNER JOIN umbracoLanguage l ON l.id = t.languageId'
+ ') AS sourceTbl PIVOT(MAX([value]) FOR languageisocode IN(' + @DynamicColumns + ')) AS pvt'
+ ' ORDER BY [key];'
execute (@DynamicSQL);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment