SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Searching for entries in subsequent log entries?
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Maverick_
Posting Yak Master

107 Posts

Posted - 12/02/2013 :  05:34:47  Show Profile  Reply with Quote
Hi guys,

I was wondering if anyone knew how I could achieve the following.

If I wanted to search for Jobs as a particular status (e.g. 0130) and wanted to keep the jobs at this status until it has reached 0500, 0125, or 0900 in it's subsequent status log entry, how can I write the SQL for it to achieve it?

I have the following SQL which searches for the Jobs at 0130, but don't know how to develop it further to search on the requirement above.


------ SQL -------
SELECT
job.job_number,
(SELECT MAX(jsl.job_log_number)
FROM job_status_log jsl
WHERE
job.job_number = jsl.job_number AND
jsl.status_code = '0130') as Last_Early_Warning_Status_Entry
FROM
action_officer,
central_site,
contract,
cost_code,
job,
job_status,
job_status_log,
priority
WHERE
central_site.site_code = job.site_code AND
cost_code.cost_code = job.cost_code AND
contract.contract_code = job.contract_code AND
priority.priority_code = job.priority_code AND
job.job_number = job_status_log.job_number AND
job.job_log_number = job_status_log.job_log_number AND
action_officer.officer_code = job_status_log.allocated_officer AND
job_status.status_code = job_status_log.status_code AND
(SELECT MAX(jsl.job_log_number)
FROM job_status_log jsl
WHERE
job.job_number = jsl.job_number AND
jsl.status_code = '0130') is not null AND
job.job_status_flag <> 'A'
ORDER BY
job.job_number desc
-----------SQL--------------

In the job_status_log table above, there is a job_log_number field which increments by 1 when there is a new status log entry.

If you have any info please let me know.

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 12/02/2013 :  07:32:55  Show Profile  Reply with Quote
can you show some sample data and explain? do you mean cases where currentjobstatus = 0130 and next log entry is one of the list (0500, 0125, or 0900) ?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000