Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 What's wrong with this !!!!

Author  Topic 

Tigger
Yak Posting Veteran

85 Posts

Posted - 2003-02-04 : 15:51:44
Can anybody see what is wrong with this?

INSERT INTO TABLE1
(
FIELD1,
FIELD2,
FIELD3,
FIELD4,
FIELD5,
FIELD6,
FIELD7,
FIELD8,
FIELD9,
FIELD10,
FIELD11,
FIELD12,
FIELD13,
FIELD14
)
SELECT
field1, -- FIELD1,
field2, -- FIELD2,
field3, -- FIELD3,
field4, -- FIELD4,
field5, -- FIELD5,
field6, -- FIELD6,
field7, -- FIELD7
field8, -- FIELD8,
field9, -- FIELD9,
field10, -- FIELD10,
field11, -- FIELD11,
field12, -- FIELD12,
field13, -- FIELD13,
field14 -- FIELD14
FROM
TABLE2


I keep getting an error message saying

"Server: Msg 120, Level 15, State 1, Line 33
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."


But unless I am going completely mad (which wouldn't surprise me !! ) the number of select values DOES match the number of insert columns -- AAAARRRGGHH!!! I've been staring at this for over an hour
now and can't see what's wrong ........

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2003-02-04 : 15:54:43
I see nothing wrong with it at all.

Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2003-02-04 : 16:08:54
Looks ok, try getting rid of the comments...also make sure you're only executing that code by highlughting it...don't know what else it could be.

Good Luck

Brett

8-)

Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2003-02-04 : 16:11:22
Are you sure it's this statement?
Try retyping it without comments to check if there are no invalid characters around.
Check if there is an insert trigger on the table which is causing the error.

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2003-02-04 : 16:26:03
I'm at a loss...cut and paste this, highlight in a query analyzer window, and execute...let us know what happens

Thanks

Brett

8-)

INSERT INTO TABLE1
(FIELD1,FIELD2
,FIELD3,FIELD4,FIELD5
,FIELD6,FIELD7,FIELD8
,FIELD9,FIELD10,FIELD11
,FIELD12,FIELD13,FIELD14)
SELECT field1,field2
,field3,field4,field5
,field6,field7,field8
,field9,field10,field11
,field12,field13,field14
FROM TABLE2


Go to Top of Page

Tigger
Yak Posting Veteran

85 Posts

Posted - 2003-02-04 : 16:36:38
Thanks for the help guys - good to see I'm not going mad!

Found the problem - or should I say fixed the problem as I still don't
know what it's problem was !

There must be some kind of hidden, invalid character on the SELECT line for field5 - by retyping that line its now all okay ... should have thought to check for invisible characters!! It's no wonder I'm going grey !!

Go to Top of Page

AndrewMurphy
Master Smack Fu Yak Hacker

2916 Posts

Posted - 2003-02-06 : 04:20:51
mmmm......I came across that problem a long time ago....(once and once only)


as usual, when all else fails.....start back at the very beginning.

Go to Top of Page

kadrove
Starting Member

13 Posts

Posted - 2003-02-28 : 18:01:10
When this happens to me it is usually caused by a missed comma in one of the lists.

Go to Top of Page
   

- Advertisement -