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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Tranfrorm data from columns to rows
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

SuzyB_24
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

sodeep
Flowing Fount of Yak Knowledge

USA
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  
 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.03 seconds. Powered By: Snitz Forums 2000