O'Reilly logo

Writing Stored Procedures for Microsoft SQL Server by Matthew Shepker

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Automating the Creation of the Code

One great thing about stored procedures is that they can save time. One stored procedure that I needed would write the code that, when executed, would be a stored procedure that would insert rows into a table. This stored procedure can be seen in Listing 7.6.

Code Listing 7.6. Automatic Creation of Stored Procedure Code
 CREATE PROCEDURE usp_create_insert_proc @vchTableName VARCHAR(64) AS SET NOCOUNT ON -- Declare the variables DECLARE @vchCurrentLine VARCHAR(128) DECLARE @vchColumnName VARCHAR(32) DECLARE @vchColumnType VARCHAR(16) DECLARE @intColumnLength INT DECLARE @bitNullable BIT DECLARE @intColNameLength INT DECLARE @intColCounter INT DECLARE @vchVariableName VARCHAR(32) -- Creates and prints the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required