• Here's the documentation on CREATE PROCEDURE. That will get you started in putting your query into a procedure. Then, as Jeff said, it's a question of calling it using the EXECUTE command.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning