Quantcast
Viewing all articles
Browse latest Browse all 5

SQL Transpose Columns

create table #t (dt date, c1 int, c2 int)

insert into #t values ('20190101',1,4)
insert into #t values ('20190101',2,5)
insert into #t values ('20190101',3,6)

select
       dt,col_value
        from
                #t
        unpivot (
                col_value for col_name in (c1, c2)) as d 
order by col_value


Best Regards,Uri Dimant SQL Server MVP,http://sqlblog.com/blogs/uri_dimant/

MS SQL optimization: MS SQL Development and Optimization
MS SQL Consulting: Large scale of database and data cleansing
Remote DBA Services: Improves MS SQL Database Performance
SQL Server Integration Services: Business Intelligence


Viewing all articles
Browse latest Browse all 5