Question : Pivot Table syntax error

I'm getting the error:
Server: Msg 170, Level 15, State 1, Line 26
Line 26: Incorrect syntax near 'PIVOT'.

Can someone see what's going on. I followed the books online sample and it looks right to me.

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
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

Answer : Pivot Table syntax error

You can use a seperate part of maintenace plan functionality to do this - Maintenance Cleanup Task:
http://msdn.microsoft.com/en-us/library/ms177182.aspx

Suggest you include it as a conditional part of the sub plan so old backups only get cleaned up once a new backup has been created.
Random Solutions  
 
programming4us programming4us