Click here to Skip to main content
15,886,788 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a dropdown list for the a number of functions like wedding,birthday etc,
and three are two table Employee,AND EmployeeStatus Table
SQL
Employee Table
id     Emp_Id  Name 
1       23      ssss
2       24      dddd
3       34       ffff

and EmployeeStatus Table
SQL
id    functionType_Id    Emp_Id    Name    Date
1        1                 23        sss   10-05-2015
2        1                 24        ddd    10-05-2015

i want that when there is more than one function on the same day ,then employee that are already used up can never used up again,rather employee that are left behind are allocated for next function for the same day.
Posted
Comments
VICK 21-May-15 1:18am    
So EmployeeStatus Table is the one in which you are saving the Function-User relationship???
VICK 21-May-15 1:20am    
Do try this.

select * from Employee
where Emp_Id not in
(
select distinct Emp_id from EmployeeStatus where Convert(date, Date) = Convert(date, 'YourDate')
)

1 solution

First thing first,
1. There is no need for Name field in the employeestatus table as it rightfully belongs to employee table, this concerns http://www.studytonight.com/dbms/database-normalization.php[^]
2. Avoid using 'date' as field name as this is a reserved word in sql and it should be of the appropriate date type not string, https://msdn.microsoft.com/en-us/library/bb630352.aspx[^]
3. Use NOT EXISTS[^] to get the result, e.g.
select * from employee e where NOT exists
(
select * from employeestatus es where e.emp_id=es.emp_id AND
  function_date = '10-05-2015'
)
 
Share this answer
 
Comments
VICK 21-May-15 2:39am    
My 5+.
Sajid227 21-May-15 6:38am    
what nice way of description,and correction,hmmmmmmm
Sajid227 21-May-15 6:59am    
bro please change this into EF Query plz??

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900