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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Tranfrorm data from columns to rows
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

United Kingdom
11 Posts

Posted - 12/11/2012 :  09:06:42  Show Profile  Reply with Quote
I have two tables, one with a list of columns relating to the hotels that a tourist will stay on during their trip and the other the details of the hotel.

This is a sample of the trip data

Id	HotelOne	HotelOneDuration	HotelOneCheckIn		HotelTwo	HotelTwoDuration	HotelTwoCheckIn		HotelThree	HotelThreeDuration	HotelThreeCheckIn	
44	129		3			2012-12-15 		127		5			2012-12-19		No Hotel		0		0001-01-01

And this the hotel data.

Id	HotelName	HotelImage	HotelText	Location	StarRatiing
129	Marriott	pic.jpg		xxx  		1		3
127	Golf Resort	golf-resort.jpg	yyy  		1		5

What I'd like to do is pull the hotel data out in rows if possible. Something like this

Position	HotelName	HotelText	Duration	CheckIn
1		Marriott	xxx		3		2012-12-15
2		Golf Resort	yyy		5		2012-12-19

Is it possible to pull the data out the database like this. Or should I just sort it out in the code.

Edited by - SuzyB_24 on 12/11/2012 09:07:23

Flowing Fount of Yak Knowledge

7174 Posts

Posted - 12/11/2012 :  09:10:23  Show Profile  Reply with Quote
Check for UNPIVOT or Union all
Go to Top of Page
  Previous Topic Topic Next 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.02 seconds. Powered By: Snitz Forums 2000