View: dbo.Journal_Entry_Account_List_View
View definition
CREATE VIEW dbo.Journal_Entry_Account_List_View
AS
SELECT journal_entry_KEY = target.journal_entry_KEY
, gl_account_number_list = replace(rtrim((
SELECT cast(outerView.gl_account_number AS VARCHAR(max)) + N' '
FROM dbo.Journal_Entry_Account_List_Detail_View outerView
WHERE journal_entry_KEY = target.journal_entry_KEY
AND NOT EXISTS (
SELECT 1
FROM dbo.Journal_Entry_Account_List_Detail_View AS innerView
WHERE outerView.journal_entry_KEY = innerView.journal_entry_KEY
AND outerView.gl_account_KEY = innerView.gl_account_KEY
AND outerView.sequence_number > innerView.sequence_number
)
ORDER BY sequence_number
FOR XML path(N'')
)), N' ', N', ')
FROM dbo.Journal_Entry AS target