Melvuen Melvuen - 5 months ago 13
Vb.net Question

Error MSG 213 Column name or number of supplied values does not match table definition

Hi I'm trying to append the result of my query to another table, but i get the an error, here is my code for the project

--create new table
create table tempweblogs
(
date1 datetime
users nvarchar(50)
utotal int
date2 datetime
hostname nvarchar(50)
htotal int
date3 datetime
srcip nvarchar(50)
stotal int
)
--insert query result to tempweblogs table

insert into tempweblogs
SELECT distinct top 10
Xdate as date1, Xuser as users, count (Xuser) as utotal
from weblogs
where Xdate='2/16/2016' and Xuser is not null
group by Xuser, Xdate order by utotal DESC

SELECT distinct top 10
Xdate as date2, Xhostname as hostname, count(Xhostname) as htotal
from weblogs
where Xdate='2/16/2016' and xhostname is not null
group by Xhostname, Xdate order by htotal DESC

SELECT distinct top 10
Xdate as date3, Xsrcip as srcip, count (Xsrcip) as stotal
from weblogs
where Xdate='2/16/2016' and Xuser is not null
group by Xsrcip, Xdate order by stotal DESC

Answer

You should need to specify the column list in the INSERT statement

insert into tempweblogs ( date1 , users , utotal )
select ....

also you need the INSERT clause for all 3 query