Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
jacowess
Starting Member
1 Post |
Posted - 2005-04-22 : 10:47:39
|
| HiI have a sproc with a lot of joins (need all the joins as the query can have multiple searches) The problem is that when searching a large record set the query times out.Do anyone have any pointers?Select Distinct Top 999 Event.EventID as Event,EventProject.ProjectName as Proj,Event.EntryDate AS Date,dbo.fn_ShortName(1,EventType.Name) as Type,Substring (EventStatus.Name,1,3) AS Status,dbo.fn_ModelOrService(Event.EventType,case when ExpEvent.eventid is null then Model.Model else ExpEvent.Model end,case when ExpEvent.eventid is null then service.Service else ExpEvent.service end)as Descrip, Geography.site + '/' + Geography.location + '/' + Geography.unit + '/' + Geography.partition AS GeographyFROM EventLEFT JOIN qfmWorkTypeLookup as WorkType ON WorkType.WorkTypeID = Event.WorkTypeIDLEFT JOIN qfmServiceGroup_ServiceLookup as service on service.ServiceID = Event.ModelORServiceIDLEFT JOIN qfmAgentOperativeLookup Operative ON Operative.AgentID = Event.AgentIDLEFT JOIN Geography ON Geography.GeographyID = Event.GeographyIDLEFT JOIN qfmSiteByGeogIDLookup AS G1 ON Event.GeographyID = G1.GeographyIDLEFT JOIN qfmGeographyRegionLookup as GeographyRegion ON GeographyRegion.regionID = G1.regionIDLEFT JOIN qfmGeographyAreaLookup as GeographyArea ON GeographyArea.regionID = GeographyRegion.AreaIDLEFT JOIN qfmSectorLookup as Region ON Region.regionID = GeographyArea.SectorIDLEFT JOIN qfmGeographySiteTypeLookup SiteType ON SiteType.GeographyID = Geography.GeographyIDINNER JOIN EventType ON Event.EventType = EventType.EventTypeIDLEFT JOIN qfmPriorityListLookup Priority ON Event.PriorityID = Priority.PriorityIDLEFT JOIN ContractorTypeRIGHT JOIN Agent ON ContractorType.ContractorTypeID = Agent.ContractorTypeID ON Event.AgentID = Agent.AgentIDLEFT JOIN qfmEventStatusLookup EventStatus ON Event.EventStatusNo = EventStatus.EventStatusIDLEFT JOIN ClientSatisfaction ON Event.ClientSatisfactionID = ClientSatisfaction.ClientSatisfactionIDLEFT JOIN qfmCostCodeLookup CostCode on Event.CostCodeID = CostCode.CostCodeIDLEFT JOIN Inventory ON Inventory.InventoryID = Event.InventoryIDLEFT JOIN qfmEquipmentGroupLookup EquipmentGroup ON Inventory.EquipmentGroupID = EquipmentGroup.EquipmentGroupIDLEFT JOIN qfmModelLookup Model ON Inventory.ModelID = Model.ModelIDLEFT JOIN qfmDepartmentsLookup Departments ON Inventory.DepartmentID = Departments.DepartmentsIDLEFT JOIN qfmDivisionLookup Division on Division.DivisionID = Inventory.DivisionIDLEFT JOIN qfmCoverCodeLookup CoverCode ON Event.CoverCodeID = CoverCode.CoverCodeIDLEFT JOIN qfmEventProjectlookup Project ON Event.EventID = Project.EventIDLEFT JOIN qfmEventProjectListLookup EventProject ON EventProject.EventsProjectId = Project.EventsProjectIdLEFT JOIN qfmSiteLocationLookup AS G2 ON Event.GeographyID = G2.GeographyIDLEFT JOIN qfmSiteByUnitLookup AS G3 ON Event.GeographyID = G3.GeographyIDLEFT JOIN qfmSiteByPartitionLookup G4 ON Event.GeographyID = G4.GeographyIDLEFT JOIN qfmAllocationLookup Allocation ON Event.CostAllocationID = Allocation.AllocationIDLEFT JOIN qfmPersonnelLookup Personnel ON Event.ReportedBy = Personnel.NameLEFT JOIN qfmOnBehalfLookup OnBehalf ON Event.OnBehalfID = OnBehalf.PersonnelIDLEFT JOIN qfmAssigneeLookup Assignee ON Event.AssigneeID = Assignee.PersonnelIDLEFT JOIN qfmContractLookup Contract ON Event.ContractID = Contract.ContractIDLEFT JOIN qfmIRInvoiceDetailLookup IRInvoiceDetail ON IRInvoiceDetail.EventID = Event.EventIDLEFT JOIN PurchaseOrderCost ON PurchaseOrderCost.EventID = Event.EventIDLEFT JOIN qfmexpresseventlookup ExpEvent ON ExpEvent.EventID = Event.EventIDWHERE (EntryDate BETWEEN '2005/Jan/06' AND '2005/Apr/20') AND (Assignee.Name BETWEEN '.DONSON RAY' AND '.DONSON RAY') ORDER BY Event.EventID DESC |
|
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2005-04-22 : 14:54:00
|
| >>need all the joins as the query can have multiple searchesDo you mean you have a lot of input parameters? In other words you have a lot of possible things to search by?If any given instance of the SP only uses a small portion of these tables, you should probably consider sp_executesql. There are several disadvantages of dynamic sql but one big advantage is being able to simplify a select statement when there are a whole bunch of optional search parameters.Be One with the OptimizerTG |
 |
|
|
|
|
|
|
|