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.

Posted on : 17-05-2012 | By : Devi Prasad | In : Msg 120, SQL Errors

0



Error Message:

Msg 120, Level 15, State 1, Line 2
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.

This error occurs when the select clause contains lesser number of columns then that present in the insert clause.

Example:

DECLARE @VTABLE table(ID INT, NAME VARCHAR(100))

INSERT INTO @VTABLE(ID,NAME)
SELECT 1

Fix/Resolution:
Make the number of columns in select statement and insert statement equal.

Update the select statement with the number of columns equal to that of insert statement.

DECLARE @VTABLE table(ID INT, NAME VARCHAR(100))

INSERT INTO @VTABLE(ID,NAME)
SELECT 1,'ABC'

Update the insert statement with the number of columns equal to that of select statement.

DECLARE @VTABLE table(ID INT, NAME VARCHAR(100))

INSERT INTO @VTABLE(ID)
SELECT 1



Reference : Devi Prasad (sqlserverlearner.com)

Do you like my blog?

If you liked reading this blog, please help spread the word by sharing this blog with your friends.



Need Help On SQL Server?

Cannot Find Solution to your problem (or) If you are looking for some help on SQL Server. Dont worry Click Here to Post your question and solve your issue.




Your Ad Here


Tags: ,