Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 How to Unpivot

Author  Topic 

vijays3
Constraint Violating Yak Guru

354 Posts

Posted - 2013-03-11 : 09:14:52
Hi All,




Furniture Retail Module 1 Furniture Retail Module 2
Passed Passed
Failed Passed

How to display above data in following manner

ModuleName Result
Furniture Retail Module 1 Passed
Furniture Retail Module 1 Failed
Furniture Retail Module 2 Passed
Furniture Retail Module 2 Passed

Kindly please suggest me on this.



Vijay is here to learn something from you guys.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-03-11 : 12:49:20
[code]
declare @test table
(
[Furniture Retail Module 1] varchar(100),
[Furniture Retail Module 2] varchar(100)
)
insert @test
SELECT 'Passed','Passed' UNION ALL
SELECT 'Failed','Passed'

SELECT ModuleName,Result
FROM @test t
UNPIVOT ( Result FOR ModuleName IN ([Furniture Retail Module 1],[Furniture Retail Module 2]))u
ORDER BY ModuleName


output
-----------------------------------------------------------
ModuleName Result
-----------------------------------------------------------
Furniture Retail Module 1 Passed
Furniture Retail Module 1 Failed
Furniture Retail Module 2 Passed
Furniture Retail Module 2 Passed

[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

vijays3
Constraint Violating Yak Guru

354 Posts

Posted - 2013-03-12 : 05:08:17
Thanks Visakh..

Vijay is here to learn something from you guys.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-03-12 : 05:13:45
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -