If I add the following:
SELECT c.name AS ExistingColOnTab2
FROM sys.columns AS c
JOIN sys.types AS t ON c.user_type_id=t.user_type_id
WHERE c.object_id = OBJECT_ID('dbo.tab2')
GO
it shows the column's name already exist in the "tab2" table.
There is a way to join the result of code abow in order to execute the following line in the new temporary table, which should be containing the name string exept the existing ones.
DECLARE @C_additional varchar(max) = '';
SELECT @C_additional= CONCAT(@C_additional, ',', <NewColumnTemporaryTable>, ' int')
FROM dbo.temporarytable
set @C_additional = stuff(@C_additional, 1, 1, ' alter table dbo.tab2 add ')t
I am sorry in advance if I make a lot of confusion