【问题标题】:Error MSG 213 Column name or number of supplied values does not match table definition错误消息 213 列名或提供的值的数量与表定义不匹配
【发布时间】:2016-06-30 03:09:42
【问题描述】:

您好,我正在尝试将查询结果附加到另一个表,但出现错误,这是我的项目代码

--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

【问题讨论】:

  • 使用这种语法时,必须期望指定的值的数量必须与表中的列数匹配。要使其工作,请在应将值放入的位置显式声明列名,例如。 INSERT INTO tempweblogs (date1, users, utotal) SELECT distinct top 10 Xdate as date1, Xuser as users, count (Xuser) as utotal ......

标签: sql-server vb.net


【解决方案1】:

您应该需要在 INSERT 语句中指定列列表

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

您还需要所有 3 个查询的 INSERT 子句

【讨论】:

    猜你喜欢
    • 2014-06-14
    • 1970-01-01
    • 1970-01-01
    • 2018-11-24
    • 1970-01-01
    • 2021-05-23
    • 2015-10-20
    • 2022-09-28
    • 2020-11-30
    相关资源
    最近更新 更多