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 |
|
velnias2010
Posting Yak Master
125 Posts |
Posted - 2010-11-22 : 12:14:40
|
| I have a query like thisSELECT CONVERT(varchar, f.FixtureDate, 106) AS stringDate, DATENAME(DW, f.FixtureDate) AS DayOfWeek, f.FixtureDate, f.Meeting, f.VenueCode, f.Evening, f.BankHoliday, f.Type, f.MeetingNum, f.Cancelled, v.Content_ID, f.FestivalFROM tbHRI_Fixtures AS f INNER JOIN tbHRI_Venue AS v ON f.VenueCode = v.RA_Venue_idWHERE (DATEDIFF(Day, f.FixtureDate, GETDATE()) <= 0)ORDER BY f.FixtureDate, f.Festival DESC, f.MeetingAnd works fine it returns dates between now and end of year.But I have a requirement for on my screens which has 7 tabs, so I want a query giving me the next 7 dates (i.e FixtureDate) column, the reason why I don't just want to do date + 7 is because some dates dont have any entries.Thanks |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
velnias2010
Posting Yak Master
125 Posts |
Posted - 2010-11-23 : 05:02:10
|
| How can I also make sure they are distinct i.e no duplicates |
 |
|
|
Ifor
Aged Yak Warrior
700 Posts |
Posted - 2010-11-23 : 06:59:08
|
| -- *** Test Data ***-- You should provide this!CREATE TABLE #t( FixtureDate smalldatetime NOT NULL)INSERT INTO #tSELECT '20101127'UNION ALL SELECT '20101127'UNION ALL SELECT '20101128'UNION ALL SELECT '20101128'UNION ALL SELECT '20101128'UNION ALL SELECT '20101129'UNION ALL SELECT '20101130'UNION ALL SELECT '20101130'UNION ALL SELECT '20101201'UNION ALL SELECT '20101202'UNION ALL SELECT '20101203'UNION ALL SELECT '20101204'UNION ALL SELECT '20101205'UNION ALL SELECT '20101206'UNION ALL SELECT '20101207'-- *** End Test Data ***SELECT DISTINCT TOP 7 FixtureDateFROM #tWHERE FixtureDate > CURRENT_TIMESTAMPORDER BY FixtureDate |
 |
|
|
|
|
|
|
|