Click here to Skip to main content
15,898,222 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have two tables one is UserTable and another is Usercompanies Table

UserTable field
1. UserId
2. UserName
3. Graduation

UserCompanies
1. Id
2. UserId
3. Company Name
4. Joining Date
5. Leaving Date
5. Currently Working

i want to select those users which have to more then 2 years experience on basis of joining and leaving date. user companies may be more then one and user can currently working in maximum 3 companies.
UserId of UserTable is foreigen key in UserCompanies Table

so please suggest me query for that
Posted
Comments
George Jonsson 4-Apr-15 1:50am    
You want to do this in c# and LINQ not SQL, right?

To come up with a solution for your question, you will need to learn about:
1. Visual Representation of SQL Joins[^]
2. http://www.w3schools.com/sql/func_datediff.asp[^]
Try to attempt it yourself first. If you are stuck while trying, then post a new question with code to ask for advice.
 
Share this answer
 
v2
Comments
Maciej Los 4-Apr-15 13:45pm    
+5 for general advice!
Peter Leow 4-Apr-15 23:03pm    
Thank you, Maciej.
C#
var query1 = UserCompanies.Where(uc => (uc.LeavingDate - uc.JoiningDate).TotalDays > 730);
var query2 =
    UserTable.Join(
                  query1,
                  u => new { u.UserId },
                  c => new { UserId = c.Id },
                  (u, c) => new { u.UserName, c }).ToList();
 
Share this answer
 
Comments
Maciej Los 4-Apr-15 13:45pm    
+5 Looks perfect!
I'd do that using one query...

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