This view will only work in the database the view is created:
and a.database_id = DB_ID() -- for current database only
(that's the only thing which comes into my mind, or there are no indexes in the database :-D )
Try cutting this view into smaller pieces, for example first query the dm_ view, add join on sysindexes etc.
WilfredThe best things in life are the simple things