I have a table like this (it is basically gonna be used for translation of our App's UI):
LangId | Container | LookupString | Translation |
---|---|---|---|
1 | MENUITEM | Active Approval Documents | Active Approval Documents |
2 | MENUITEM | Active Approval Documents | 審核方案 |
3 | MENUITEM | Active Approval Documents | 审核方案 |
1 | MENUITEM | Active Project | Active Project |
2 | MENUITEM | Active Project | 處理中 |
3 | MENUITEM | Active Project | 处理中 |
1 | BUTTON | Add | Add |
2 | BUTTON | Add | 新增 |
3 | BUTTON | Add | 新增 |
Test table:
INSERT INTO @CultureStringResource
VALUES
(1,'MENUITEM', 'Active Approval Documents', 'Active Approval Documents'),
(2,'MENUITEM', 'Active Approval Documents', N'審核方案'),
(3,'MENUITEM', 'Active Approval Documents', N'审核方案'),
(1,'MENUITEM', 'Active Project', 'Active Project'),
(2,'MENUITEM', 'Active Project', N'處理中'),
(3,'MENUITEM', 'Active Project', N'处理中'),
(1,'BUTTON', 'Add', 'Add'),
(2,'BUTTON', 'Add', N'新增'),
(3,'BUTTON', 'Add', N'新增')
I would like to query against this table, and sort of group the translation in 1 line.
The desired result should look like following.
LangId | Container | LookupString | English | Chinese_tranditional | Chinese_simplified |
---|---|---|---|---|---|
1 | MENUITEM | Active Approval Documents | Active Approval Documents | 審核方案 | 审核方案 |
1 | MENUITEM | Active Project | Active Project | 處理中 | 处理中 |
1 | BUTTON | Add | Add | 新增 | 新增 |
I can achieve this by running this query:
SELECT
c1.LanguageId, c1.Container, c1.LookupString, c1.Translation,
(SELECT Translation
FROM @CultureStringResource
WHERE LanguageId = 1
AND LookupString = c1.LookupString) AS English,
(SELECT Translation
FROM @CultureStringResource
WHERE LanguageId = 2
AND LookupString = c1.LookupString) AS Chinese_traditional,
(SELECT Translation
FROM @CultureStringResource
WHERE LanguageId = 3
AND LookupString = c1.LookupString) AS Chinese_simplified
FROM
@CultureStringResource c1
WHERE
LanguageId = 1
By using this query, I would need to change the query every time there is a new language (lang_id
) added to the table,
Is there any better way to do this so it will automatically select 1 more column for every distinct lang_id
inserted?