TSQL dynamic adding of columns in stored procedure?

Try this: declare @sql nvarchar(100) set @sql = 'ALTER TABLE reports ADD '+ @columnname+' VARCHAR(50) NULL exec sp_executesql @sql.

Try this: declare @sql nvarchar(100) set @sql = 'ALTER TABLE reports ADD '+ @columnname+' VARCHAR(50) NULL' exec sp_executesql @sql.

Cannot get around having to do it dynamically I believe so change your BEGIN block to something like this: DECLARE @sql VARCHAR(8000) BEGIN SET @sql = 'ALTER TABLE Table_1 ADD '+@columnname+' VARCHAR(50) NULL' EXEC(@sql) END.

Try DECLARE @columnname VARCHAR(50) SET @columnname = 'on_' + @description +'' IF NOT EXISTS(SELECT * FROM syscolumns WHERE id = OBJECT_ID('reports') AND NAME = @columnname) BEGIN ALTER TABLE reports ADD @columnname VARCHAR(50) NULL END.

Hi I am writing a large stored procedure, which creates a dynamic report table, of n columns in size, the first 6 are constant the remainder depend on a few arguments passed to the procedure to create the table with the required columns. I am getting syntax errors with this at the @columnname in the ALTER TABLE statement of the above code. Also as I am new to this, I am not sure if this is the best way to do this, or if there are better ways in TSQL to generate the required dynamic table.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions