This code is a modification to the above post to have the cities adjusted under each other
Create TABLE #tempCityState (State Varchar(5), City Varchar(50))
Insert Into #tempCityState
Select 'CO', 'Denver' Union
Select 'CO', 'Teluride' Union
Select 'CO', 'Vail' Union
Select 'CO', 'Aspen' Union
Select 'CA', 'Los Anggeles' Union
Select 'CA', 'Hanford' Union
Select 'CA', 'Fremont' Union
Select 'AK', 'Wynne' Union
Select 'AK', 'Nashville';
with States as (
select distinct
State
from
#tempCityState
)
select
State,
stuff((select CHAR(9) + ' ' + City + char(13) + char(10)
from #tempCityState tcs
where tcs.State = States.State
order by tcs.City
for xml path(''),TYPE).value('.','varchar(max)'), 1, 3, '') as Cities
from
States;
Drop table #tempCityState