Long island web design, hosting company
Home About Us Support Products Services Portfolio Contact Us Home

TSQL > How to create a dynamic stored procedure

Created On: 7/14/2005 2:03:00 PM

This examples shows you how to create a dynamic stored procedure in MSSQL:
CREATE procedure test_dynamic_sp
@Param1 char(3)
AS
-- Declares the variable that will hold your SQL Statement
Declare @SQL varchar(255)
SET @SQL = 'select * from customers ' +
    ' where customername=''' + @Param1 + '''' + ' and active=''1'''
Exec ( @SQL )
GO