Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Vertical to Horizontal 1

Status
Not open for further replies.

mayamanako

Technical User
Aug 31, 2005
113
GB
hi guys, can you please give me an idea how i can convert the table below:

Code:
name   col1  col2  col3
fruits  111   222   333
veg     444   555   666

and to have a recordset that's something like this?

Code:
name   col1  col2  col3  vegname  vegcol1  col2  col3
fruits  111   222   333     veg     444     555   666

thanks for any help.


 
Hi,

A question: always have those rows (2 rows)?
depending of this , below it's a sample code


SQL:
;with yourTbl as
(select 'fruits' as [name],  111 as col1,  222 as col2,   333 as col3 union all
 select 'veg',     444,   555  , 666 )


 select F.name as fruitName,F.col1 as fruitCol1,F.col2 as fruitCol2,F.col3 as fruitCol3, 
	V.name as vegName,V.col1 as vegcol1,V.col2 as vegcol2,v.col3 as vegcol3
 from 
 (select name,col1,col2,col3
  from yourTbl
  where name='fruits') as F
  cross join
  (
  select name,col1,col2,col3
  from yourTbl
  where name='veg'
  ) as V

Ce-am pe mine am si-n dulap, cand ma-mbrac zici ca ma mut
sabin
 
Hi sabinUE,

That's awesome! This is exactly what I needed. Thanks v much!
 
with welcome
glad to help



Ce-am pe mine am si-n dulap, cand ma-mbrac zici ca ma mut
sabin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top