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.
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/2010GAN2010100 16/10/2010GAN2010100 17/10/2010HEP2010210 15/10/2010HEP2010210 19/10/2010HEP2010210 20/10/2010JIY2010155 15/10/2010JOK2010157 17/10/2010JOK2010157 18/10/2010But 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/2010GAN2010100 17/10/2010HEP2010210 15/10/2010HEP2010210 20/10/2010JIY2010155 15/10/2010JOK2010157 17/10/2010JOK2010157 18/10/2010Can 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_CodeUNIONSELECT 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. |
 |
|
|
|
|