I would like to add around 50 columns to table defined as variable. Names of those columns are coming from another table and basically they are just numbers - DEPA_KEY. (department key)
Is it possible to add those columns dynamically with loop or something similar?
Table defined as variable (here I would like dynamically add 50 columns):
DECLARE @USERS TABLE
(
USER_KEY INT,
USDE_HSU DECIMAL(8,2)
)
Query for all departments:
SELECT DEPA_KEY FROM CADEPA