Additional SQL Server features and topics not covered by specific categories
I see from your comment you're stuck in the pre-SQL 2017 world where STRING_AGG is not an option. In that case, use FOR XML instead for defined behavior:
SELECT @SQL = (SELECT COALESCE(AlterTableSQL,'')
FROM CustomRegisters_CustomFields
WHERE LogId = @id
ORDER BY id
FOR XML PATH(''), TYPE).value('(./text())[1]', 'NVARCHAR(MAX)');
SELECT @SQL;
GO