• Looking at the code you posted, I have no idea where to start. There actually isn't much to work with.

    You can start by reading these articles:

    http://www.sqlservercentral.com/articles/T-SQL/66097/

    http://www.sqlservercentral.com/articles/T-SQL/66494/