I have the following xml document
<XML_Articles>
<Articles>
<ID>12</ID>
<ReferenceNum>123</ReferenceNum>
<ArName>الهدف</ArName>
<EnName>GOAL</EnName>
<PublicationDate>2016-11-15</PublicationDate>
<TypeID>15</TypeID>
<CreatedBy>2</CreatedBy>
<CreatedOn>2016-11-15</CreatedOn>
</Articles>
</XML_Articles>
insert them into table by
INSERT INTO dbo.Articles
(ReferenceNum,ArName,EnName,PublicationDate,PublisherID,TypeID,CreatedBy,CreatedOn)
SELECT * FROM OPENROWSET(BULK 'C:\Users\dana_\Desktop\DataBase\Assignments\Assignement 6\Articles.xml',SINGLE_BLOB) AS x
But I get an 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.
Best Answer
This error is fairly self-explanatory. The number of columns in the 'insert' column list do not match the number of columns in the 'select' column list. Check the number of columns being returned by your SELECT * I would suggest that it is rarely a good idea to use SELECT * when trying to insert into another table. You should always explicitly specify the selected columns.
I played around with your example XML data by putting it in a file and then executed the following