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
 General SQL Server Forums
 New to SQL Server Programming
 Need to display the column values into rows

Author  Topic 

chennaraaj
Starting Member

17 Posts

Posted - 2013-06-25 : 23:55:26
Hi,

i have table like

Lot_No Heat_No Pipe_No Test_result

123109556 725.3087 E30311 Accepted
123111000 705.4673 E30322 Accepted
123110579 716.4903 E30284 Accepted

i need to show the result like below what i have give

Lot_No 123109556
Heat_No 725.3087
Pipe_No E30311
Test_result Accepted

Lot_No 123111000
Heat_No 705.4673
Pipe_No E30322
Test_result Accepted





rk

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-06-26 : 00:13:04
SELECT *
FROM (SELECT CAST(Lot_No AS VARCHAR(10)) Lot_No, CAST(Heat_No AS VARCHAR(10)) Heat_No, Pipe_No, Test_result FROM tableName) U
Unpivot ( val for col in (Lot_No , Heat_no, Pipe_No, Test_result))

--
Chandu
Go to Top of Page

chennaraaj
Starting Member

17 Posts

Posted - 2013-06-26 : 01:20:14
quote:
Originally posted by bandi

SELECT *
FROM (SELECT CAST(Lot_No AS VARCHAR(10)) Lot_No, CAST(Heat_No AS VARCHAR(10)) Heat_No, Pipe_No, Test_result FROM tableName) U
Unpivot ( val for col in (Lot_No , Heat_no, Pipe_No, Test_result))

--
Chandu




hi chandu,

i am getting error like...

Msg 102, Level 15, State 1, Line 3
Incorrect syntax near ')'.


rk
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-06-26 : 02:36:12
[code]
SELECT col,val
FROM (SELECT CAST(Lot_No AS VARCHAR(20)) Lot_No, CAST(Heat_No AS VARCHAR(20)) Heat_No, CAST(Pipe_No AS varchar(20)) AS Pipe_no, CAST(Test_result AS varchar(20)) AS Test_result,ROW_NUMBER() OVER (ORDER BY Lot_No) AS Seq FROM tableName) t
Unpivot ( val for col in (Lot_No , Heat_no, Pipe_No, Test_result))u
ORDER BY Seq
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

chennaraaj
Starting Member

17 Posts

Posted - 2013-06-26 : 02:45:47
quote:
Originally posted by chennaraaj

Hi,

i have table like

Lot_No Heat_No Pipe_No Test_result

123109556 725.3087 E30311 Accepted
123111000 705.4673 E30322 Accepted
123110579 716.4903 E30284 Accepted

i need to show the result like below what i have give

Lot_No 123109556
Heat_No 725.3087
Pipe_No E30311
Test_result Accepted

Lot_No 123111000
Heat_No 705.4673
Pipe_No E30322
Test_result Accepted





rk




Thanks lot both of you...

rk
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-06-26 : 02:53:00
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -