Generally speaking, in an application variables are used with stored procedures to insert records into a table. Since we have covered how to create and assign variables, let's see how to incorporate this into a stored procedure.
Let's explain this code before we begin executing it:
The top two lines with the 'CREATE PROCEDURE' logic indicate a new stored procedure will be created followed by the input parameters and their associated data type. As you can see from the last example, the declarations section has been moved to the 'CREATE PROCEDURE' logic and the variables are not initialized at this point in time.
The 'AS' indicates the body of the stored procedure code will follow.
The next section starting with '/*' and ending with '*/' are comments. This stored procedure has a comment block that I typically use. For more information about comments, check out the Comment SQL Server TSQL Code tip.