Declare @MarkDate datetime
SET @MarkDate = '7/15/2010'
Truncate Table tbl_Metrics_AutoLoad
Insert Into tbl_Metrics_AutoLoad(COBDate) Values(@MarkDate)
Create Table #MARKS(Amt INT, Type varchar(50) )
Insert Into #MARKS(Amt, Type)
Select COUNT([ID]) as [Margin Calls Aged >1 Day], 'Margin Calls Aged >1 Day'
From tbl_Calls
Where MarkDate = @MarkDate AND
[Date Entered] < MarkDate
Insert Into #MARKS(Amt, Type)
Select COUNT([ID]) as [Total Margin Call Disputes], 'Total Margin Call Disputes'
From tbl_Calls
Where MarkDate = @MarkDate AND
CallAgreed = 'DISPUTE'
Select 'Amt' as Metric, [Margin Calls Aged >1 Day], [Total Margin Call Disputes]
From
(Select Amt, Type From #MARKS) as SourceTable
PIVOT
(
SUM(Amt)
FOR Type IN ( [Margin Calls Aged >1 Day], [Total Margin Call Disputes] )
) as PivotTable
Drop Table #MARKS
|