Reputation: 1
I want to order columns of data separately - i.e. have both columns ordered by value independently of one another (removing the links between data in each columns). How can I do this without using multiple 'select' clauses?
Upvotes: 0
Views: 1081
Reputation: 13141
I don't think it can be done any simpler than this (SQL Server):
;with cte as (
select
COLUMN_NAME, DATA_TYPE ,
rwn1 = ROW_NUMBER() over(order by column_name),
rwn2 = ROW_NUMBER() over(order by data_type)
from INFORMATION_SCHEMA.COLUMNS
)
select
c1.COLUMN_NAME, c2.DATA_TYPE
from cte c1
join cte c2
on c1.rwn1=c2.rwn2
order by
c1.rwn1
Upvotes: 1