| Author |
Topic |
|
benkennedy
Starting Member
5 Posts |
Posted - 2008-10-02 : 10:29:55
|
| Hello all.Needing some help.I have 3 tables.Drill 1 Table:Date Employee1/1/08 123441/2/08 234591/7/08 34568etc.Drill 2 Table:Date Employee1/2/08 456721/4/08 901241/6/08 56788etc.Employee Table:EmpNum Name12344 John B Green23348 Johnny S Red23459 Sam A Brown34568 Jack C Blue45672 Jess L Yellow59535 Mason J Orange90124 Rich G Black56788 Matt R GraySo if i enter StartDate: 1/1/08 and EndDate: 1/4/08I would like the output of:EmployeeNum EmployeeName23348 Johnny S Red34568 Jack C Blue59535 Mason J Orange56788 Matt R GrayThis query is for a report in SQL Server Business Intelligence Development Studio on SQL Server 2005Thanks!Ben |
|
|
bjoerns
Posting Yak Master
154 Posts |
Posted - 2008-10-02 : 10:35:45
|
| select EmployeeNum, EmployeeName from Employeewhere EmployeeNum in(23348, 34568, 59535, 56788)order by EmployeeNum ascWhat's the logic behind? Those who do not have an entry between 1/1/08 and 1/4/08? Hard to guess from expected output. |
 |
|
|
benkennedy
Starting Member
5 Posts |
Posted - 2008-10-02 : 10:37:58
|
| Basically I need to report those employees who haven't had a drill in the time period specified |
 |
|
|
bjoerns
Posting Yak Master
154 Posts |
Posted - 2008-10-02 : 10:42:02
|
| And the datatypes of Date and EmployeeNum? |
 |
|
|
benkennedy
Starting Member
5 Posts |
Posted - 2008-10-02 : 10:48:16
|
| Date is DateTime And EmployeeNum nchar(5) |
 |
|
|
bjoerns
Posting Yak Master
154 Posts |
Posted - 2008-10-02 : 11:04:32
|
| [code]select EmpNum, Namefrom Employeeleft join( select Date, Employee from Drill1 union all select Date, Employee from Drill2) Drillson Employee.Empnum = Drills.Employeeand Drills.Date between '01/01/2008' and '01/04/2008'where Drills.Employee IS NULL[/code] |
 |
|
|
benkennedy
Starting Member
5 Posts |
Posted - 2008-10-02 : 11:17:27
|
| Thanks!I'll try that, but in the meantime I have come up w/ this:SELECT EmpNum, NameFROM EmployeeWHERE (NOT EXISTS (SELECT Employee FROM Drill1 WHERE (Employee.EmpNum = Employee) AND (Date BETWEEN '01/01/2008' AND '01/04/2008') UNION SELECT Employee FROM Drill2 WHERE (Employee.EmpNum = Employee) AND (Date BETWEEN '01/01/2008' AND '01/04/2008')))What do you think? |
 |
|
|
bjoerns
Posting Yak Master
154 Posts |
Posted - 2008-10-02 : 11:24:43
|
| Sure, should be equivalent :) |
 |
|
|
benkennedy
Starting Member
5 Posts |
Posted - 2008-10-02 : 11:26:33
|
| It figures that I work on this query for 3 days, and when I ask for help the answer comes to me. But Thanks anyway. |
 |
|
|
|