Monday, May 21, 2012

To add column in table through stored procedure

ALTER PROCEDURE [dbo].[insert_column]

-- Add the parameters for the stored procedure here

@columnname as VARCHAR(max),
@datatype as VARCHAR (max)
AS
DECLARE @SQL nvarchar(500)
DECLARE @Colm nvarchar(50)
DECLARE @type nvarchar(50)

SET @Colm = @columnname
SET @type = @datatype

SET @SQL = 'ALTER TABLE ParsedResumeData ADD '+@colm+' '+@type+'
DEFAULT 0'
EXEC sp_executesql @SQL,N'@columnname as VARCHAR(max),
@datatype as VARCHAR (max)',@columnname,@datatype