I ran into the error: The select list for the INSERT statement contains fewer items than the insert list. The number of SELECT values must match the number of INSERT columns.
Well I’ve run into it often.
Normally this simply means you have specified fewer items in values for an INSERT statement than you have specified you need. For example:
INSERT INTO Table1
( ID, [Column], Column1 )
SELECT 1,
'Value',
Now, that’s easily rectified, by including the columns you need or removing the one from INSERT you do not need.
However, I also noticed that in my situation I had all the columns needed, but I was lacking a comma – like this:
INSERT INTO Table1
( ID, [Column], Column1 )
SELECT 1,
'Value1'
'Value2'
Notice the lack of comma between Value1 and Value2.
This gives the mentioned error and not a syntax error in the SELECT statement. The reason is that SQL Server concatenates the Value1 and Value2 fields into one column, and therefore the SELECT only produces 2 columns.
SQL Server will be able to concatenate two columns into one without needing to add them together, but only two columns.
So if I were to forget the third comma I would get an “Incorrect syntax near Value2″ error message alerting me to the issue. But forget one comma between 2 columns and you get no such information.
I didn’t see a mention of this in the MSDN documentation.