How can i add new column in a temporary table based on the query result. Consider the code below
declare @ctr int
set @ctr = 1
while (@ctr <= (select count(*) from #temp2)
begin
alter table #temp
add (select t2.Value from #temp2 t2 where t2.SysID = @ctr) (select t2.Type from #temp3 t3 where t3.SysID = @ctr)
end
something like that. I have some syntax error about this but as far as i know my syntax is correct
you’ll have to use dynamic SQL. This is something that I have done before:
this probably doesn’t cover every possible datatype but for my requirements, it was enough. In any case, a good place to start