Use
Query analyzer &
SQL Profiler of SQL Server to find the query cost and performance. See where the bottle neck is and try to fine tune it.
References:
Query Analyzer, find at location:
- Programs > Microsoft SQL Server 2008 R2 > SQL Server Management Studio for Query Analyzer.
- Programs > Microsoft SQL Server 2008 R2 > Performance Tools > SQL Server Profiler for profiler.
Views in DB:
MSDN: Create VIEW[
^]
Overview of Views in SQL Server 2005[
^]
You are using cursors which is not considered good practice, try TableValue functions instead and see.