SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Need to display the column values into rows
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

chennaraaj
Starting Member

India
17 Posts

Posted - 06/25/2013 :  23:55:26  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

India
2224 Posts

Posted - 06/26/2013 :  00:13:04  Show Profile  Reply with Quote
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

India
17 Posts

Posted - 06/26/2013 :  01:20:14  Show Profile  Reply with Quote
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

India
52325 Posts

Posted - 06/26/2013 :  02:36:12  Show Profile  Reply with Quote

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


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

chennaraaj
Starting Member

India
17 Posts

Posted - 06/26/2013 :  02:45:47  Show Profile  Reply with Quote
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

India
52325 Posts

Posted - 06/26/2013 :  02:53:00  Show Profile  Reply with Quote
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000