views:

457

answers:

2

Could any one show me how to get record from this statement

  • Select random employee which is not an employee of the month in the last x months

Table Employee
ID
EmployeeName

Table EmployeeOfTheMonth
ID
EmployeeID
MonthStartedDate
MonthEndedDate

Thank you very much

+2  A: 
select top 1 id from employee as emp 
where not exist(
    select top 1 * 
      from employeeofthemonth as em 
      where em.id = emp.id and dateadd(m, -6, getdate()) < monthendeddt )
order by newid()

... or something close to that. i didn't run the sql, but on mssql server, this should be about right.

Don Dickinson
Seems like he wanted something in Linq.
Keltex
What are the performance implications of this query? Looks as if it could become a bit of a bottleneck as the number of records increase.
A: 
Galkin