Case with new column name
-
Saturday, November 17, 2012 1:38 PM
Hi
Please kindly help me I am new to t-sql
I have a View which Gives data in single row and I need to alter that in the following way.
All Replies
-
Saturday, November 17, 2012 1:44 PMModerator
Use the UNION operator.
UNION ALL example:
http://www.sqlusa.com/bestpractices/unionall/
Kalman Toth SQL 2008 GRAND SLAM
New Book: Beginner Database Design & SQL Programming Using Microsoft SQL Server 2012- Edited by Kalman TothMicrosoft Community Contributor, Moderator Saturday, November 17, 2012 1:46 PM
-
Saturday, November 17, 2012 1:56 PM
Hallo Kodi,
with respect - what a data design. But it's EXECL, isn't it. Sometimes I think some developers think about SQL Server as a huge EXCEL workbook where you can enter hundreds of thousand of sheets (named tables) :)
Well - back to your requirements. Kalman gave you the hint for a solution. This example based on your data may help.
USE Indexing GO IF OBJECT_ID('dbo.foo') IS NOT NULL DROP TABLE dbo.foo GO CREATE TABLE dbo.foo ( ColA char(2), ColB char(2), ColC char(2), NRX1 int, NRX2 int, NRX3 int, TRX1 int, TRX2 int, TRX3 int ); INSERT INTO dbo.foo VALUES ('NY', 'CA', 'PA', 1, 2, 3, 11, 12, 13); SELECT ColA, ColB, ColC, 'NRX' AS Indicator, NRX1 AS Month1, NRX2 AS Month2, NRX3 AS Month3 FROM dbo.foo UNION SELECT ColA, ColB, ColC, 'TRX' AS Indicator, TRX1 AS Month1, TRX2 AS Month2, TRX3 AS Month3 FROM dbo.fooUwe Ricken
MCITP Database Administrator 2005
MCITP Database Administrator 2008
MCITP Microsoft SQL Server 2008, Database Development
db Berater GmbH
http://www-db-berater.de
SQL Server Blog (german only)- Marked As Answer by KODI_KODI Saturday, November 17, 2012 2:17 PM
-
Saturday, November 17, 2012 10:43 PMThank you
-
Saturday, November 17, 2012 10:43 PMThank you

