tags:

views:

131

answers:

1

Hi,

i think the title is a little cryptic, here's what i want to do...

i have in my tabel two datetime fields. Now i want to select the rows where the largest (ie the most far in the future) date is larger than 'today'

few examples: (today is 6-22)
date1: null, date2: null : no match, all lower than now
date1: null, date2: 5-31: no match, all lower than now
date1: null, date2: 6-23: match, 6-23 is larger than now
date1: 5-31, date2: 7-23: match, 6-23 is larger than now
date1: 7-21, date2: 1-23: match, 7-21 is larger than now
date1: 7-21, date2: null: match, 7-21 is larger than now

so in sort of pseudo code:

select * from table where (max(date2, date2)) > now

Regards, Michel

+5  A: 

Is this what you want (I converted your SQL):

from row in table
where (row.Date1 != null && row.Date1 > DateTime.Now) || 
      (row.Date2 != null && row.Date2 > DateTime.Now)
select row
Mehrdad Afshari
if i look at this, i see the linq query right in front of me i think.Just thinking to difficult with the Linq statements sometimes.
Michel