Quantcast
Channel: SQLServerCentral » SQL Server 2014 » Development - SQL Server 2014 » Latest topics
Viewing all articles
Browse latest Browse all 3145

Convert Columns to Rows

$
0
0
Hi I have data in this format,[code="sql"]CREATE TABLE [dbo].[Example]( [AZ] INT NULL, [NY] INT NULL, [PA] INT NULL)GO INSERT [dbo].[Example] ([AZ], [NY], [PA]) VALUES ('5', '7', '5')INSERT [dbo].[Example] ([AZ], [NY], [PA]) VALUES ('2', '3', '5')INSERT [dbo].[Example] ([AZ], [NY], [PA]) VALUES ('3', '2', '5')SELECT * FROM [dbo].[Example][/code]I need to display them such as,State TotalAZ 10NY 12PA 15I m trying something like this and got stuck,SELECT State,total FROM [dbo].[Example]UNPIVOT ( SUM(AZ) FOR

Viewing all articles
Browse latest Browse all 3145

Trending Articles