There has to be a better way then doing this, obviously SQL is not one of my strong points, which I'm trying to correct now lol
Should I be using sub-queries?
Code:SELECT sr.id , sr.description , sr.report , sr.note AS internalNote , st.name AS serviceType , wo.id AS woid , c.name AS companyName , c.id AS cid , DATE_FORMAT(sr.dateCreated,'%m/%d/%Y @ %h:%i %p') AS dateCreated , ROUND((TIME_TO_SEC(sr.endtime) - TIME_TO_SEC(sr.starttime)) / 3600.0 , 2 ) AS totalHours , ROUND((TIME_TO_SEC(sr.endtime) - TIME_TO_SEC(sr.starttime)) / 3600.0 , 2 ) - sr.deduction AS totalTime , DATE_FORMAT(sr.startTime,'%c/%e/%Y - %h:%i %p') AS startTime , DATE_FORMAT(sr.endTime,'%c/%e/%Y - %h:%i %p') AS endTime , sr.deduction , s.name AS status , e.mfrName , e.model , e.serial , l.name AS locationName , srn.note , DATE_FORMAT(srn.postedOn,'%m/%d/%Y @ %h:%i %p') AS noteDate , t.firstName , t.lastName , rt.name as rateName FROM service_report AS sr LEFT JOIN work_orders as wo ON wo.id = sr.woid LEFT JOIN company AS c ON sr.cid = c.id LEFT JOIN enum_status as s ON sr.status = s.id LEFT JOIN equipment as e ON sr.eid = e.id LEFT JOIN locations as l ON e.location = l.id LEFT JOIN enum_service_type as st ON sr.serviceType = st.id LEFT JOIN service_report_notes as srn ON sr.id = srn.srid LEFT JOIN technicians as t ON srn.postedBy = t.id LEFT JOIN enum_rate_type as rt ON sr.rateType = rt.id WHERE sr.id = ?



Reply With Quote






Bookmarks