Hi,
I am trying to Dynamically add a column and also update the temp table. But I am getting error message like “Server: Msg 170, Level 15″. Is there any way that I can solve this. Very urgent. Thanks in advance. My code goes like this.
set @tempvar = ‘name’ + convert(char(2),@count)
set @tempvar = ltrim(rtrim(convert(varchar(25),@tempvar)))
if not exists (select * from syscolumns
where id=object_id(‘#tbl2’) and name= ‘@tempvar’)
ALTER TABLE #tbl2 ADD @tempvar varchar(25) NULL
set @set = ‘ SET ‘ + ltrim(rtrim(convert(varchar(250),@tempvar)))+ ‘= ‘ + ”” + @child +””
set @update = ‘UPDATE #tbl2’
set @where5 = ‘Where father = ‘+ ””+ ltrim(rtrim(convert(varchar(20),@father)))+ ””
set @SQL = @update + @set + @where5
exec(@SQL)