SQL Server 2008 – I want to concatenate four columns into delimited values, but I want them to be ordered alphabetically. Is this possible?
**UPDATE:**More info… This will be used on approx 700k-1M rows per day in an ETL job via SSIS. If there is an easier way to do it within SSIS, please let me know (script task, etc). It could also be done within a Stored Proc.
Also keep in mind that these can be NULL – which is throwing some issues in with some of these solutions.
This requirement might indicate a problem with your design. If the values in the 4 columns are semantically equivalent you will likely find putting it into first normal form and refactoring the repeating columns out into a new table will make this sort of problem easier.
A monster
CASEstatement will probably be much more efficient but here’s one way withoutGives