February 1, 2011 at 12:47 pm
Hi
I have a Table with all the details of Employee along with the Title.
I want to know the list of employees with Title as App Dev II anytime during the Year.
For Example i was App Dev I untill Nov and my title Changed to App Dev II in Nov. i want my self in the List.Any Idea's about it?
Also i have other request that want to Get salary of Employee as of 01/01/2011 .
Help appreciated Need help ASAP
Thanks
February 1, 2011 at 1:00 pm
do you have a table that does an audit or history for when someone changes their title?
so if i got promoted to "Developer 3" , is that stored in a related table to your main table you described, or is the main table updated directly with no audit?
if there is no audit table, there is no way to get the "differences" ...there's nothing to compare it to.
SQL does not keep a history of data changes like that , unless you have an auditing trigger, or CDC(sql 2008) or C2 auditing, or your own custom trace running.
Lowell
February 1, 2011 at 1:13 pm
Hi Lowell
We have a History table but like Emp is my current table and EmpHistory is our History table .
Emp Table only have current table and EmpHistory has the dates when the title is changed and when it is effective from
February 1, 2011 at 1:28 pm
rakkpra (2/1/2011)
Hi LowellWe have a History table but like Emp is my current table and EmpHistory is our History table .
Emp Table only have current table and EmpHistory has the dates when the title is changed and when it is effective from
without the definitions of the tables, i can only guess....remember I'm not in your cubicle looking over your shoulder, you have to show us what you've got.
as a wild guess it's a simple join between the main table and hte history. it's going to be something like this:
select *
from myEmployees
left outer join myEmployeesHistory
On myEmployees.ID = myEmployeesHistory.ID
Where myEmployeesHistory.DateOfChange BETWEEN '20100701 00:00:00.000' AND '20101231 00:00:00.000'
Lowell
February 1, 2011 at 1:29 pm
we can't really give you the SQL to use as we don't have the table structures, however assuming that EmpID is the key in your EmpTable and that EmpHistory has a foreign Key of EmpID. The following should come close:
select E.EmpFirstName, E.EmpLastName, E.Title, H.ChangeDate, H.PreviousTitle
from Emp E
join EmpHistory H on E.EmpID = H.EmpID
where E.Title = 'App Dev II' or
(H.Title = 'App Dev II' and H.ChangeDate >= '01/01/2011')
--------------------------------------------------------------------------
When you realize you've dug yourself into a hole....Step 1...stop digging.
February 1, 2011 at 1:31 pm
Lowell's is better than mine as it takes the possibility of not having a history record into account. Heh heh.
--------------------------------------------------------------------------
When you realize you've dug yourself into a hole....Step 1...stop digging.
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply