Hi,
Here is the Code to Add column dynamically in a table
Declare @ColumnName as Varchar(50)
declare @ssql nvarchar(200)
Set @ColumnName ='Column1'
set @ssql = 'Alter table TableName Add ' + @ColumnName + ' int'
exec sp_executesql @ssql
Here is the code to add dynamic column with data type
Declare @ColumnName as Varchar(50)
declare @ssql nvarchar(200)
declare @DataType nvarchar(200)
Set @ColumnName ='Column1'
Set @DataType ='Bigint'
set @ssql = 'Alter table TableName Add ' + @ColumnName + ' ' +@DataType
exec sp_executesql @ssql
1 comment:
Great Shaalini. Keep it up.
Post a Comment