SQL Server: Ordering by date in the future when year is not known -


i have information table: due date day , month (eg. 16/11 16th november) of events repeat every year.

i need create view, sorted how far in future.

(eg. if 16 nov 2010, 31/12 means 31 dec 2010 , comes before 1/1 means 1 jan 2011)

let's assume event table has these 3 columns

|------------------------| |         event          | |------------------------| | id | dueday | duemonth | |------------------------| 

thanks in advance!

any event in table dues day/month ahead of current day/month occur *this*year. event due day/month behind current day/month occur next year. event due next year further event due year.

now being said, ask not possible because ask ...a view, sorted by... concept not exists. views not sorted. queries sorted. can create view projects proper event date , query view must use order by events sorted event date:

create table events (  id int identity(1,1) not null,   dueday int not null,   duemonth int not null); go  insert events (dueday, duemonth)  values  (1,1), (15,11), (31,12); go  create view eventsdate select id, dateadd(day, dueday-1,   dateadd (month, duemonth-1,      dateadd(year,           case when duemonth < month(getdate()) or             (duemonth = month(getdate()) ,               dueday < day(getdate()))          year(getdate())-1899          else year(getdate())-1900 end,           '19000101'))) duedate     events; 

to events order, query must include order by:

select * eventsdate order duedate desc; 

Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -