【问题标题】:Msg 213, Level 16, State 1, Procedure cp_iso_extract, Line 32 Insert Error: Column name or number of supplied values does not match table definition消息 213,级别 16,状态 1,过程 cp_iso_extract,第 32 行插入错误:列名或提供的值的数量与表定义不匹配
【发布时间】:2017-04-03 19:02:17
【问题描述】:

消息 213,级别 16,状态 1,过程 cp_iso_extract,第 32 行 插入错误:列名或提供的值的数量与表定义不匹配。

我需要以下查询方面的帮助。我已经匹配了填充、插入和输出部分,我没有看到任何名称或大小方面的问题。任何帮助是极大的赞赏。

USE [Allegro]
GO

/****** Object:  StoredProcedure [dbo].[cp_iso_extract]    Script Date: 11/29/2016 2:26:23 PM ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE procedure [dbo].[cp_iso_extract]

    as

set nocount on

--CREATE HEADER RECORD TABLE UH01
declare @uh01 table
(UH01 char(10),            --required field
 custcode char(9),        --required field
 processdatetime char(14),     --required field
 version char(4),          --required field
 filler char(475))         --required field

--POPULATE THE HEADER RECORD TABLE UH01
insert into @uh01
select '000000UH01', + --filetype
'S73200001', + --custcode
REPLACE(REPLACE(REPLACE(CONVERT(VARCHAR(14), CONVERT(DATETIME, getdate(), 112), 126), '-', ''), 'T', ''), ':', ''), --processdatetime
'US01',   --version
space(475) --filler

--Create output tables
declare @output1 table (data char(512))
declare @output2 table (data char(512))



--Insert header record into #output1
insert into @output1
select rtrim(UH01) + space(10 - len(UH01)),            --required field
rtrim(custcode) + space(9 - len(custcode)),       --required field
rtrim(processdatetime) + space(14 - len(processdatetime)),       --required field
rtrim(version) + space(4 - len(version)),       --required field
space(475) --filler         --required field
from @uh01 

 --CREATE UA01 TABLE
declare  @ua01 table
(UA01 char(10),                 --required field
 reporttype char(1),            --required field
 inscompanycode char(9),        --required field
 policynum char(30),            --required field
 policytype char(4),            --required field
 policyinceptiondate char(8),
 policyexpate char(8),
 policyrenewalind char(1),
 riskpolicyind char(1),
 claimno char(30),              --required field
 dateofloss char(8),            --required field
 timeofloss char(4),
 CatIndicator char(1),
 cat char(3),
 companyrecdate char(8),
 lossdesc char(50),
 loclossaddr1 char(50),
 loclossaddr2 char(50),
 loclosscity char(25),
 loclossst char(2),             --required field
 loclosspostal char(9),
 loclosscountry char(3),        --required field
 filler char(4),
 agencynotifiedofloss char(35),
 policefirereportnum char(15),
 routingmisinfo char(20),
 nosearchind char(1),
 datefirstclaimpayment char(8),
 fundclaim char(1),
 vesselcallnum char(50),
 apdfastcheckindicator char(1),
 legacyclaimconversionind char(1),
 requestclaimconversionind char(1),
 policereportinoccurenceind char(1),
 singlevehicleaccidentindicator char(1),
 phantomvehaccind char(1),
 wasaccwitnessed char(1),
 molddamage char(1),
 filler2 char(1),
 filler3 char(2),
 hitandrun char(1),
 reqrecallind char(1),
 masstortind char(1),       --required field
 selfinsuredind char(1),
 cobcassignedsectionID char(9),
 tin char(9),
 siteid char(9),
 nmvtisoprepid char(7),
 filler4 char(9),           --required field
 filler5 char(5))           --required field

 --POPULATE THE UA01 table
insert into @ua01
select '000000UA01', --UA01
'I', --reporttype
'S73200001', --inscompanycode
isnull(rtrim(convert(char(30), po.policyid)), space(30)) --policynum
'PAPP', --policytype
isnull(left(convert(char(8), po.inceptdt, 112), 8), space(8)), --policyinceptiondate
isnull(left(convert(char(8), po.expiratdt, 112), 8), space(8)), --policyexpate
space(1), --policyrenewalind
space(1), --riskpolicyind
isnull(convert(char(30), c1.agencynumb), space(30)), --Claim Number
isnull(left(convert(char(8), c.doi, 112), 8), space(8)), --dateofloss
isnull(left(convert(char(4), c.accdtime, 114), 4), space(4)), --timeofloss
space(1), --CatIndicator
space(3), --cat@
isnull(left(convert(char(8), c.lworkdate, 112), 8), space(8)), --companyrecdate
space(50), --lossdesc
space(50), --loclossaddr1 
space(50), --loclossaddr2
space(25), --loclosscity
convert(char(2),c1.jurst), --loclossst
space(9), --loclosspostal
'USA', --loclosscountry
space(4), --filler
space(35), --agencynotifiedofloss
space(15), --policefirereportnum
space(20), --routingmisinfo
space(1), --nosearchind
space(8), --datefirstclaimpayment
space(1), --fundclaim
space(50), --vesselcallnum
space(1), --apdfastcheckindicator
space(1), --legacyclaimconversionind
space(1), --requestclaimconversionind
space(1), --policereportinoccurenceind
space(1), --singlevehicleaccidentindicator
space(1), --phantomvehaccind
space(1), --wasaccwitnessed
space(1), --molddamage
space(1), --filler2
space(2), --filler3
space(1), --hitandrun
space(1), --reqrecallind
space(1), --masstortind 
case
  when ca.invmsg like 'SELF%' then 'Y' 
  else 'N'
 end,       --selfinsuredind
space(9),  --cobcassignedsectionID
space(9).   --tin
space(9),   --siteid
space(7),   --nmvtisoprepid
space(9),   --filler4
space(5)    --filler5

from claim c
join claim1 c1 on c.claimno = c1.lnkclaimno
join claim2 c2 on c.claimno = c2.link2claim
join person p on c.patient = p.personid
join cmpolicy cm on c.claimno = cm.claimno
join policy po on cm.policyid = po.policyid
join carrier ca on c.carrier = ca.code


--Insert claim records into #output2
insert into @output2
select rtrim(UA01) + space(10 - len(UA01)),         --required field  --Record indicator
rtrim(reporttype) + space(1 - len(reporttype)), --reporttype
rtrim(inscompanycode) + space(9 - len(inscompanycode)), --inscompanycode
rtrim(policynum) + space(30 - len(policynum)),--Claimant number
rtrim(policytype) + space(4 - len(policytype)),  --policytype   --required field
space(8) + --policyinceptiondate 
space(8) + --policyexpate 
space(1) + --policyrenewalind
space(1) + --riskpolicyind
rtrim(claimno) + space(30 - len(claimnum)),         --required field
rtrim(dateofloss) + space(8 - len(dateofloss)),     --required field
space(4) + --timeofloss
space(1) + --CatIndicator
space(3) + --cat@
space(8) + --companyrecdate 
space(50) + --lossdesc
space(50) + --loclossaddr1
space(50) + --loclossaddr2
space(25) + --loclosscity 
rtrim(loclossst) + space(2 - len(loclossst)),       --required field
space(9) +    --loclosspostal 
rtrim(loclosscountry) + space(3 - len(loclosscountry)),     --required field
space(4) +  --Filler
space(35) + --agencynotifiedofloss
space(15) + --policefirereportnum 
space(20) + --routingmisinfo 
space(1) + --nosearchind 
space(8) + --datefirstclaimpayment
space(1) + --fundclaim 
space(50) + --vesselcallnum 
space(1) + --apdfastcheckindicator
space(1) + --legacyclaimconversionind
space(1) + --requestclaimconversionind 
space(1) + --policereportinoccurenceind 
space(1) + --singlevehicleaccidentindicator
space(1) + --phantomvehaccind 
space(1) + --wasaccwitnessed 
space(1) + --molddamage 
space(1) + --filler2 
space(2) + --filler3 
space(1) + --hitandrun
space(1) + --reqrecallind
rtrim(masstortind) + space(3 - len(masstortind)),       --required field
rtrim(selfinsuredind) + space (1 - len(selfinsuredind)), --selfinsuredind 
space(9) + --cobcassignedsectionID
space(9) + --tin 
space(9) + --siteid 
space(7) + --nmvtisoprepid 
space(9) + --filler4            --required field
space(5)    --filler5           --required field
from @ua01

【问题讨论】:

    标签: sql-server insert output temp-tables


    【解决方案1】:

    @output1 有一列,但您尝试在其中插入多列。

    declare @output1 table (data char(512))
    ...
    insert into @output1
    select rtrim(UH01) + space(10 - len(UH01)),            --required field
    rtrim(custcode) + space(9 - len(custcode)),       --required field
    rtrim(processdatetime) + space(14 - len(processdatetime)),       --required field
    rtrim(version) + space(4 - len(version)),       --required field
    space(475) --filler         --required field
    from @uh01 
    

    【讨论】:

      猜你喜欢
      • 2014-06-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-09
      • 1970-01-01
      • 2014-01-22
      • 2016-04-17
      相关资源
      最近更新 更多