I’m trying to select different variables into a temporary table as individual rows, but I’m being advised that ‘there are fewer columns in the insert statement than values specified…’ How would I insert these as individual rows?
x
INSERT INTO ##TestTable (Errors)
VALUES( (@Error1),
(@Error2),
(@Error3),
(@Error4),
(@Error5),
(@Error6),
(@Error7)
)
Advertisement
Answer
Your first parenthesis considered as first column, you need to separate them
INSERT INTO ##TestTable (Errors)
SELECT t.Errors
FROM (VALUES (@Error1), (@Error2), (@Error3), (@Error4), (@Error5), (@Error6), (@Error7)
) t(Errors);
You can also leave it :
VALUES (@Error1),
(@Error2),
(@Error3),
(@Error4),
(@Error5),
(@Error6),
(@Error7)