存储过程:列名称或提供的值数与表定义不匹配

时间:2017-04-04 19:06:07

标签: sql-server stored-procedures insert populate

完全丢失此存储过程。我逐行检查,一切似乎都匹配。非常感谢任何帮助。

错误我得到了:

  

Msg 213,Level 16,State 1,Procedure cp_iso_extract,Line 95
  插入错误:列名或提供的值数与表定义不匹配。

第95行

selfinsuredind char(1),

这是我的代码:

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(CHAR(14), CONVERT(DATETIME, getdate(), 112), 126), '-', ''), 'T', ''), ':', ''), --processdatetime
            'US01',   --version
            space(475) --filler

    --Create output table 1
    declare @output1 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

--Insert header record into #output1
insert into @output1
select 
isnull(rtrim(convert(char(10), UH01)), space(10)),            --required field
isnull(rtrim(convert(char(9), custcode)), space(9)),       --required field
isnull(rtrim(convert(char(14), processdatetime)), space(14)),       --required field
isnull(rtrim(convert(char(4), version)), space(4)),       --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

declare @output2 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


--Insert claim records into #output2
insert into @output2
select 
isnull(rtrim(convert(char(10), UA01)), space(10)),          --required field  --Record indicator
isnull(rtrim(convert(char(1), reporttype)), space(1)), --reporttype
isnull(rtrim(convert(char(9), inscompanycode)), space(9)), --inscompanycode
isnull(rtrim(convert(char(30), policynum)), space(30)),--Claimant number
isnull(rtrim(convert(char(4), policytype)), space(4)),  --policytype   --required field
space(8), --policyinceptiondate 
space(8), --policyexpate 
space(1), --policyrenewalind
space(1), --riskpolicyind
isnull(rtrim(convert(char(30), claimno)), space(30)),           --required field
isnull(rtrim(convert(char(8), dateofloss)), space(8)),      --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 
isnull(rtrim(convert(char(2), loclossst)), space(2)),       --required field
space(9),    --loclosspostal 
isnull(rtrim(convert(char(3), loclosscountry)), space(3)),      --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
space(1), --masstortind
isnull(rtrim(convert(char(1), selfinsuredind)), space(1)),  --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

1 个答案:

答案 0 :(得分:4)

您似乎在insert into @ua01

上的policynum行上错过了一个逗号
...
'S73200001', --inscompanycode
                                                        \/
isnull(rtrim(convert(char(30), po.policyid)), space(30)), --policynum
                                                        /\
'PAPP', --policytype
...