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 |
gvmk27
Starting Member
44 Posts |
Posted - 2012-06-13 : 10:24:40
|
Hi I have table with 2 column's 1. calendardate(date) 2. GroupId(int) Consecutive dates will be stored with groupid, anddate will be stored in mm/dd/yyyy format.01/01/2012 101/02/2012 101/03/2012 102/01/2012 202/02/2012 202/03/2012 2 06/11/2012 306/12/2012 306/13/2012 306/21/2012 406/22/2012 406/23/2012 4I need to write a sql which displays start date and end date of each group. If end date of a group is less than today's date, I should not display that record.so the output of above table should be 06/11/2012 - 06/13/201206/21/2012 - 06/23/2012I was trying like this, but not getting expected result. SELECT GroupId, min(CalendarDate) as StartDate, max(CalendarDate) as EndDate FROM CenterDateExclusionSetting WHERE CenterGUID = @CenterGUID AND CalendarDate > GETDATE() GROUP BY GroupIdThanks for your help in advance. |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-06-13 : 10:34:46
|
[code]SELECT GroupId, min(CalendarDate) as StartDate, max(CalendarDate) as EndDate FROM CenterDateExclusionSetting WHERE CenterGUID = @CenterGUIDGROUP BY GroupIdHAVING max(CalendarDate) >= CAST(GETDATE() AS date)[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
gvmk27
Starting Member
44 Posts |
Posted - 2012-06-13 : 10:49:04
|
Thanks Visakh..quote: Originally posted by visakh16
SELECT GroupId, min(CalendarDate) as StartDate, max(CalendarDate) as EndDate FROM CenterDateExclusionSetting WHERE CenterGUID = @CenterGUIDGROUP BY GroupIdHAVING max(CalendarDate) >= CAST(GETDATE() AS date) ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
|
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-06-13 : 10:50:21
|
wc------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
|
|
|