Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Equipment Maintenance Query

Status
Not open for further replies.

Melanie1

IS-IT--Management
Apr 10, 2008
4
0
0
US
I am trying to write a query to display any equipment that is due to be sent in for yearly maintenance. It should run off of the creation date of the equipment entry if it hasn't been sent in before. If it has been sent in, it needs to run off of the closed date of our service call.

I created a case statement to display a column of the date I would like it to use (called 'Start Date'). First of all, how can I display only the most recent service call date if there are multiple service calls for that piece of equipment? Second, how can I use this case result in my where clause to show everything greater than a year from the 'Start Date'?

Any help would be greatly appreciated!! Below is what I have so far (OINS is the equipment card table and OSCL is the service call table):

Set ANSI_NULLS off

SELECT T0.[insID], T0.[manufSN], T0.[customer], T0.[itemCode], T0.createdate, T1.createdate, T1.closedate,

CASE T1.createdate
when NULL then T0.createdate
else T1.closedate
end AS 'Start Date'

FROM OINS T0 LEFT JOIN OSCL T1 ON T0.insID = T1.insID

WHERE T0.status = 'A'
 
that's pretty cheeky, posting in the ANSI SQL forum when the first thing you do is set ANSI_NULLS off (why do you feel this is necessary, by the way?)

next time you will probably want to post in forum183

:)

Code:
SELECT OINS.[insID]
     , OINS.[manufSN]
     , OINS.[customer]
     , OINS.[itemCode]
     , OINS.createdate
     , OSCL.createdate
     , OSCL.closedate
     , COALESCE(OSCL.closedate
               ,OINS.createdate) AS 'Start Date'
  FROM OINS 
LEFT OUTER
  JOIN OSCL 
    ON OSCL.insID = OINS.insID
   AND OSCL.closedate = 
       ( SELECT MAX(closedate)
           FROM OSCL
          WHERE insID = OINS.insID )
 WHERE OINS.status = 'A'

r937.com | rudy.ca
 
Sorry. I was working on multiple queries yesterday and forgot that was in there. Thanks for the information!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top