Hi,Got these two sets:SELECT RequestID, RequestTypeID, RequestStatusID ,"DateApproved" = (SELECT DateApproved FROM Ticket T Where T.TicketID = CR.TicketID) ,"DateFirstReleased" = (DateFirstReleased) ,"ProductionDays" = ( DateDiff(day, (SELECT DateApproved FROM Ticket T Where T.TicketID = CR.TicketID) , (DateFirstReleased) ) ) ,"TicketCompletedDate" = (SELECT CompletedDate FROM Ticket T Where T.TicketID = CR.TicketID)FROMMyDatabase.dbo.CustomRequest CRWHERE DateDeactivated is null AND CR.RequestTypeID <> 1
SELECT RequestID, RequestTypeID, RequestStatusID ,"DateApproved" = (SELECT DateApproved FROM Ticket T Where T.TicketID = CR.TicketID) ,"DateFirstReleased" = (SELECT NewAsOfDate FROM MyDatabase.dbo.Report R Where R.ReportID = CR.ReportID AND IsDotNetActive =1) ,"ProductionDays" = ( DateDiff(day, (SELECT DateApproved FROM Ticket T Where T.TicketID = CR.TicketID) , (SELECT NewAsOfDate FROM MyDatabase.dbo.Report R Where R.ReportID = CR.ReportID AND IsDotNetActive =1) ) ) ,"TicketCompletedDate" = (SELECT CompletedDate FROM Ticket T Where T.TicketID = CR.TicketID)FROMMyDatabase.dbo.CustomRequest CRWHERE DateDeactivated is null AND CR.RequestTypeID = 1
How can I combine in one single data set while keeping good performance? I was using CASE on one ProductionDays and DateFirstReleased, but SQL engine is making two Index Spools when I do that. I tried UNION ALL but it's even worse as the engine reads the tables twice.