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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Need help to show the data in a format

Author  Topic 

ganny
Yak Posting Veteran

51 Posts

Posted - 2010-12-15 : 01:54:47
Hi,

i have values in the table like below format.

Booking_Code Booking_Date
-------------------------------
GAN2010100 15/10/2010
GAN2010100 16/10/2010
GAN2010100 17/10/2010
HEP2010210 15/10/2010
HEP2010210 19/10/2010
HEP2010210 20/10/2010
JIY2010155 15/10/2010
JOK2010157 17/10/2010
JOK2010157 18/10/2010

But i need only the first and last date of Booking_Code when it has multiple dates, i.e. Each booking_code should contain only 2 dates (first & last) like below format.

Booking_Code Booking_Date
-------------------------------
GAN2010100 15/10/2010
GAN2010100 17/10/2010
HEP2010210 15/10/2010
HEP2010210 20/10/2010
JIY2010155 15/10/2010
JOK2010157 17/10/2010
JOK2010157 18/10/2010

Can anyone please help me how to get the result as requested above format.

Thanks for your help.

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-12-15 : 02:54:53
SELECT Booking_Code, MIN(Booking_Date) as Booking_Date FROM Table GROUP BY Booking_Code
UNION
SELECT Booking_Code, MAX(Booking_Date) as Booking_Date FROM Table GROUP BY Booking_Code



No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -