Hi
I want to add column through function in table by sqlserver please define how to add column?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
dalachha SolankiPosted Jan 21, 2015, 4:47 AM
pradip vaghaniPosted Jan 21, 2015, 4:41 AM
EXEC dbo.AddColumn @TableName = 'users', -- nvarchar(max)
@Columnname = 'city', -- nvarchar(max)
@Datatype = 'varchar(20)' -- nvarchar(max)
dalachha SolankiPosted Jan 21, 2015, 4:25 AM
pradip vaghaniPosted Jan 21, 2015, 4:04 AM
(
@TableName NVARCHAR(max),
@Columnname NVARCHAR(max),
@Datatype NVARCHAR(max)
)
RETURNs int
AS
begin
DECLARE @Status int
SET @Status=1
DECLARE @Sql NVARCHAR(max)
SET @Sql = 'ALTER TABLE '+ @TableName +' ADD '+@Columnname+' '+@Datatype
exec sp_executeSql @Sql
RETURN @Status
END