Filtering Join Tables by Date

I need to Filter Employees by Available Date and grab their Basic contact information

I used Join to Join both tables  but I can't seem to find a way to only get data from employees where DateAv > SelectedDate.

I'm using this in a SqlCommand with C#. 

SELECT " EmployeeNameTable.ID, EmployeeNameTable.FullName,

EmployeeNameTable.DateAV,ContactTable.HomePhone,

ContactTable.MobilePhone, ContactTable.Email

FROM EmployeeNameTable INNER JOIN ContactTable

On EmployeeNameTable.ID = ContactTable.ID

OrderBy EmployeeNameTable.FullName"

This code loads all employees Successfully but it doesn't filter them by the DateAV Column which is in Date Format.

September 14th, 2015 6:03pm

Is this what you're looking for?

DECLARE @employees TABLE (employeeID INT, availableDate DATETIME)
INSERT INTO @employees (employeeID, availableDate) VALUES
(1, '2015-09-14'),(2, '2015-09-10'),(3, '2015-09-20'),(4, '2015-09-19')

DECLARE @contacts TABLE (employeeID INT, contactID INT, phone NVARCHAR(20))
INSERT INTO @contacts (employeeID, contactID, phone) VALUES
(1,1, '123-456-7890'),(2,2, '123-456-7890'),(3,3, '123-456-7890'),(4,4, '123-456-7890')

SELECT *
  FROM @employees e
    INNER JOIN @contacts c
	  ON e.employeeID = c.employeeID

 WHERE availableDate > '2015-09-14'

Free Windows Admin Tool Kit Click here and download it now
September 14th, 2015 6:09pm

>> I need to Filter Employees by Available Date and grab their Basic contact information <<

Please follow basic Netiquette and post the DDL we need to answer this. Follow industry and ANSI/ISO standards in your data. You should follow ISO-11179 rules for naming data elements. You have no idea about this basic standard. I will try to correct a few things for you until you can get some help. 

Putting -table is so bad, we call it a tibble and laugh at it. 
Names are an attribute, so they will not get a table of their own. Your silly Employee_Name_Table would be a column in a Personnel table! There is no generic id in RDBMS; it has to be <particular entity>_id 

You should follow ISO-8601 rules for displaying temporal data (https://xkcd.com/1179/). We need to know the data types, keys and constraints on the table. Avoid dialect in favor of ANSI/ISO Standard SQL. 

Please tell me how you are able to program without DDL? 

>> I used Join to Join both tables  but I can't seem to find a way to only get data from employees where DateAv > Selected Date. <<

Hre is how to re-write your query with the 

SELECT P.emp_id, P.full_name, 
       P.available_date, - NO!! not in this table. 
       C.homephone_nbr, C.mobilephone_nbr, C.email_address
 FROM Personnel AS P,
       Contacts AS C 
WHERE P.emp_id = C.emp_id;

>> this code loads all employees successfully but it doesn't filter them by the dateav column which is in date format. <<

DATE is a data type, not a format. AGAIN, where is that DDL? The state of "being available" begs the question, Available for what? Marriage? Employment? A discount?

Availability is a relationship, not an attribute. Relationship have their own tables. This is covered in the first 2-3 weeks of any RDBMS class. This is why we have Authors, Books and the relation Authorship in a valid model. Guys like you would make a book a part of the author or the author part of the book!  NO!! 

Want to follow forum rules and try again? 
September 14th, 2015 7:29pm