Totally agree with heer2351,
If its not to late change it, if you dont know how ask but dont continue with this design.
It will only make getting any usefull data from your db almost impossible.
Main Topics
Browse All TopicsI have 10 fields in my table, each corresponding to a date that a department got this particular job.
What I want to find out is the latest date field (last department that had this job), and the name of the field.
Finding the name of the field is the hard part for me. finding the latest date itself is easy with some if statemtents such as "if date2 > date1 then latestdate = date2"
How do I assign another variable such as LastDep with the actual field name that holds this latest date (The other fields would be null if they haven't reached that department yet)?
Another hard part is that it is possible that different departments can start different parts of the job at different times, and it's also possible that multiple departments could have the same signout date if they are all done with their portion at the same time.
In this situation, Ideally, I would want a list of the departments and then the date... If one date is higher than the rest, I would just want a single department and the date itself.
Example of how I want the output:
If multiple departments finish at one time: "Dep2, Dep3, Dep5 - 7/11/2005"
If one date is later than the rest: "Dep7 - 7/11/2005"
If you need some better clarification, please let me know.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
First you create the new tables then you use queries like this:
insert into tblJobs (jobDescription)
select distinct
Job
from
yourTable
and:
assuming fields in yourTable are named Dep1, Dep2, Dep3 ...
insert into tblDepartmentJobs (department, jobID, startdate)
select distinct
'Dep1', tblJobs.jobID, Dep1
from
tblJobs inner join yourTable on tblJobs.jobDescription=you
you have to run the above query as many times as you have department fields in yourTable. Change each time the department field name and the description. For example for Dep5
insert into tblDepartmentJobs (department, jobID, startdate)
select distinct
'Dep5', tblJobs.jobID, Dep5
from
tblJobs inner join yourTable on tblJobs.jobDescription=you
Business Accounts
Answer for Membership
by: heer2351Posted on 2005-07-11 at 15:28:25ID: 14417043
Sounds like your database has not been setup correctly. You have a table with 10 fields, I assume one field for each department, correct?
tJobs.jobI D
tJobs.jobI D
It would be better to have two tables, one for the jobs and one for departments and their start dates:
tblJobs
jobID Number
jobDescription Text
tblDepartmentJobs
department Text
jobID Number
startDate Date
You can then use queries like:
select
jobDescription, department, max(date)
from
tblJobs inner join tblDepartmentJobs on tblJobs.jobID=tblDepartmen
group by
jobDescription, department
You could reduce that to a single job by adding a where clause like:
select
jobDescription, department, max(date)
from
tblJobs inner join tblDepartmentJobs on tblJobs.jobID=tblDepartmen
where
tblJobs.jobID=3
group by
jobDescription, department