Fun with T-SQL

Concatenate table of strings into single string in T-SQL without cursors

Created using recursive CTEs. Run in SQL 2008.

See other SQL fractals

T-SQL Source

with data(t) as 
	select 'aaa '
	union select 'bbb '
	union select 'ccc '
	union select 'ddd '
orderedData(t,n) as
	select t, row_number() over (order by t) from data
strings(s, depth) as
	select cast('' as nvarchar(max)), cast(max(n) as int)
		from orderedData
	union all
	select d.t + s.s, s.depth-1
		from strings s
		join orderedData d on s.depth = d.n	
select s from strings where depth=0


See other SQL fractals