I have a stored procedure that creates a pivot query. The problem I'm having is that the inner query is returning 1641 records, then when the pivot is executed, only 1450 records make it to the result set.
The query is as follows:
SELECT CallSegments.AppName, CH.CallDate, dbo.fn_IsContacted(CH.AppName, CH.Result) AS Contacted, CallSegments.QueueID, dbo.fn_GetResultCategory( CallSegments.AppName, CH.Result ) AS CallResult
FROM CallSegments, CallHistory AS CH WHERE CH.CallInstance = CallSegments.CallInstance
AND RTRIM( CallSegments.AgentID ) = '
AND RTRIM( CallSegments.QueueID ) <> '
AND CH.AppName = 'some_client'
AND CH.CallDate >= '11/3/2009 00:00:00.000' AND CH.CallDate <= '11/3/2009 23:59:59.997'
The interesting thing, for me, is that I can copy the internal select clause and run it separately. When it executes, I receive 1641 records in the result. Then when it goes throug the pivot, records are dropped. I don't quite understand because all of the
inner records have a category listed in the pivot list. I've looked it over several times but I just can't see where I'm losing records.
View Complete Post