无法理解错误:

时间:2013-10-07 09:53:47

标签: sql sql-server-2008-r2 runtime-error

SELECT 
   CAST(dbo.TrnRisk.VehDriverName AS VARCHAR(100))
 , CAST(dbo.VieClaimRegister.ClientID AS VARCHAR(100))
 , CAST(dbo.VieClaimRegister.FileNo AS VARCHAR(100))
 , CAST(dbo.VieClaimRegister.ClaimNo AS VARCHAR(100))
 , CAST(dbo.VieClaimRegister.NameInitials AS VARCHAR(100))
 , CAST(dbo.VieClaimRegister.LossDate AS VARCHAR(100))
 , CAST(dbo.MstInsurer.ABSAInsurerName AS VARCHAR(100))
 , CAST(dbo.VieClaimRegister.AgentID + ' ' + ISNULL(dbo.MstAgent.AgentName, 'Unknown')AS VARCHAR(100)) AS AgentIDName 
 , CAST(dbo.VieTeamSelect.SubRegionID + ' ' + ISNULL(dbo.VieTeamSelect.SubRegionName, 'Unknown')AS VARCHAR(100)) AS SubRegionIDName
 , CAST(dbo.VieClaimRegister.TeamID + ' ' + ISNULL(dbo.VieTeamSelect.TeamName, 'Unknown')AS VARCHAR(100)) AS TeamIDName
 , CAST(dbo.VieClaimRegister.LinkID + ' ' + ISNULL(dbo.MstLink.LinkName, 'Unknown')AS VARCHAR(100)) AS LinkIDName
 , CAST(dbo.TrnPolicy.BrokerContact + ' ' + ISNULL(MstHandler.BrokerName, 'Unknown')AS VARCHAR(100)) AS BrokerIDName
 , CAST(ISNULL(dbo.VieClaimRegister.AssessorID,'None') + ' ' + ISNULL(dbo.MstClaimAssessors.AssesorID,'Unknown')AS VARCHAR(100)) AS AssessorIDName
 , CAST(dbo.VieClaimRegister.OwnDamage AS VARCHAR(100))
 , CAST(dbo.VieClaimRegister.ThirdParty AS VARCHAR(100))
 , CAST(dbo.VieClaimRegister.ThirdPartyEstimate AS VARCHAR(100))
 , CAST(dbo.VieClaimRegister.Paid AS VARCHAR(100))
 , CAST(dbo.VieClaimRegister.Estimate AS VARCHAR(100))
 , CAST(dbo.VieClaimRegister.OwnDamageEstimate AS VARCHAR(100))
 , CAST(dbo.VieClaimRegister.SubSection AS VARCHAR(100))
 , CAST(dbo.VieClaimRegister.DriverAge AS VARCHAR(100))

 -- RiskCoverDays looks at first item on risk table in order to get risk inception date.
 -- If there are multiple items then we only look at the earliest risk inception date.
 -- Not quite correct, but a big improvement over the old Access database and
 -- easy enough to program ...

 , CAST(dbo.VieClaimRegister.RiskDeletion AS VARCHAR(100))
 , CAST(dbo.VieClaimRegister.ReportDate AS VARCHAR(100))
 , CAST(dbo.VieClaimRegister.CauseID AS VARCHAR(100))

 -- Make/ model description without Mead & McGrouther code:

 , CAST(dbo.VieClaimRegister.VehModel AS VARCHAR(100))
 , CAST(dbo.VieClaimRegister.ClientStatusCode AS VARCHAR(100))

 -- The following are intended to be outside the printable area in the spreadsheet:

 , CAST(dbo.VieClaimRegister.SectionID AS VARCHAR(100))
 , CAST(dbo.VieClaimRegister.RiskNo AS VARCHAR(100))
 , CAST(dbo.VieClaimRegister.LossDate AS VARCHAR(100))
 , CAST(dbo.TrnPolicy.InceptionDate AS VARCHAR(100))
 , CAST(dbo.VieClaimRegister.DateLoaded AS VARCHAR(100))
 , CAST(dbo.VieClaimRegister.ReportDate AS VARCHAR(100))
 , CAST(dbo.VieClaimRegister.SettledDate  AS VARCHAR(100))

 -- How many weeks from the load date to the report date as per F1:

 , CAST(dbo.VieClaimRegister.SettledDate AS VARCHAR(100))
 , CAST(dbo.VieClaimRegister.LossDate AS VARCHAR(100))
 , CAST(dbo.VieClaimRegister.ClaimPostalID AS VARCHAR(100))
 , CAST(dbo.VieClaimRegister.FastTrack AS VARCHAR(100))
 , CAST(dbo.VieClaimRegister.ExGratia AS VARCHAR(100))
 , CAST(dbo.VieClaimRegister.HandlerID + ' ' + ISNULL(dbo.MstHandler.BrokerName,'Unknown')AS VARCHAR(100)) AS HandlerIDName
 , CAST(dbo.VieClaimRegister.K4K AS VARCHAR(100))
 , CAST(dbo.VieClaimRegister.Registration AS VARCHAR(100))
 , CAST(dbo.VieClaimRegister.ClaimsLinkID AS VARCHAR(100))
 , CAST(dbo.MstUser.UserName AS VARCHAR(100)) AS ClaimsLinkName
 , CAST(dbo.VieClaimRegister.Repudiation AS VARCHAR(100))
 , CAST(dbo.VieClaimRegister.InsurerID AS VARCHAR(100))
 , CAST(dbo.VieClaimRegister.Fees AS VARCHAR(100))
 , CAST(dbo.VieClaimRegister.Expenses AS VARCHAR(100))
 , CAST(dbo.VieClaimRegister.Recoveries AS VARCHAR(100))
 , CAST(dbo.VieClaimRegister.Salvages AS VARCHAR(100))
 , CAST(dbo.VieClaimRegister.RecoveriesEstimate AS VARCHAR(100))
 , CAST(dbo.VieClaimRegister.SalvagesEstimate AS VARCHAR(100))
 , CAST(ISNULL(ThirdPartyEstimate,0)AS VARCHAR(100)) AS EstimateThirdParty
 , CAST(ISNULL(dbo.VieEstimateMovement.EstimateMovement,0)AS VARCHAR(100)) AS ClaimMovement
 , CAST(VieClaimRegister.AuthorisedDate AS VARCHAR(100))
 , CAST(VieClaimRegister.TeamID AS VARCHAR(100))
 , CAST(VieClaimRegister.AgentID AS VARCHAR(100))
 , CAST(VieClaimRegister.LinkID AS VARCHAR(100))
 , CAST(VieClaimRegister.InsurerID AS VARCHAR(100)) AS InsurerIDForFilter

 -- How many days from the load date to the authorised date(claim turn around time)

 , Cast(MstProduct.BusinessArea AS VARCHAR(100))


 FROM dbo.VieClaimRegister

 LEFT  JOIN dbo.MstUser ON 
    dbo.VieClaimRegister.ClaimsLinkID = dbo.MstUser.UserID
 LEFT JOIN dbo.TrnClient ON
dbo.VieClaimRegister.ClientID = dbo.TrnClient.ClientID
 LEFT JOIN dbo.TrnPolicy ON 
dbo.VieClaimRegister.ClientID = dbo.TrnPolicy.ClientID
AND dbo.VieClaimRegister.FileNo = dbo.TrnPolicy.FileNo
 LEFT JOIN dbo.VieEstimateMovement On
dbo.VieClaimRegister.ClientID = dbo.VieEstimateMovement.ClientID
AND dbo.VieClaimRegister.FileNo = dbo.VieEstimateMovement.FileNo
AND dbo.VieClaimRegister.ClaimNo = dbo.VieEstimateMovement.ClaimNo


 -- VieTeamSelect includes MstTeam, MstSubRegion, MstRegion, MstCompany:

 LEFT JOIN dbo.VieTeamSelect ON 
dbo.VieClaimRegister.TeamID = dbo.VieTeamSelect.TeamID

 -- Link code is as per claim table, not policy table (!) :

 LEFT JOIN dbo.MstLink ON 
dbo.VieClaimRegister.LinkID = dbo.MstLink.LinkID
 LEFT JOIN dbo.MstAgent ON 
dbo.VieClaimRegister.AgentID = dbo.MstAgent.AgentID
 LEFT JOIN dbo.MstInsurer ON

 -- Insurer code is as per claim table, not policy table (!) :

dbo.VieClaimRegister.InsurerID = dbo.MstInsurer.InsurerID
 LEFT JOIN dbo.MstInsurer MstInsurerLead ON

 -- Insurer code is as per claim table, not policy table (!) :

dbo.VieClaimRegister.InsurerID = MstInsurerLead.InsurerID
LEFT OUTER JOIN TrnRisk ON 
VieClaimRegister.ClientID = TrnRisk.ClientIDo
AND VieClaimRegister.FileNo = TrnRisk.FileNo 
AND VieClaimRegister.RiskNo = TrnRisk.RiskID
 LEFT OUTER JOIN dbo.MstHandler ON 
VieClaimRegister.HandlerID = dbo.MstHandler.BrokerID 
AND TrnPolicy.BrokerContact = MstHandler.BrokerID
 LEFT OUTER JOIN dbo.MstClaimAssessors ON 
dbo.VieClaimRegister.AssessorID = dbo.MstClaimAssessors.AssesorID
 LEFT JOIN dbo.MstProduct ON 
dbo.TrnPolicy.ProductID= dbo.MstProduct.ProductID

这是一个SQL查询,用于访问要在Reporting Services中使用的一组数据。但是,它给我一个错误“将varchar值'Absa Insurance and Financial Advisers(Pty)Limited'转换为数据类型int时转换失败。”甚至在将所有内容都转换为Varchar之后。我还是SQL的新手,所以任何帮助都将不胜感激。很抱歉,这么长时间,有很多数据可供使用。

2 个答案:

答案 0 :(得分:2)

我的猜测是你需要将这些语句中的ID值转换为varchar:

 , CAST(dbo.VieClaimRegister.AgentID + ' ' + ISNULL(dbo.MstAgent.AgentName, 'Unknown')AS VARCHAR(100)) AS AgentIDName 
 , CAST(dbo.VieTeamSelect.SubRegionID + ' ' + ISNULL(dbo.VieTeamSelect.SubRegionName, 'Unknown')AS VARCHAR(100)) AS SubRegionIDName
 , CAST(dbo.VieClaimRegister.TeamID + ' ' + ISNULL(dbo.VieTeamSelect.TeamName, 'Unknown')AS VARCHAR(100)) AS TeamIDName
 , CAST(dbo.VieClaimRegister.LinkID + ' ' + ISNULL(dbo.MstLink.LinkName, 'Unknown')AS VARCHAR(100)) AS LinkIDName
 , CAST(dbo.TrnPolicy.BrokerContact + ' ' + ISNULL(MstHandler.BrokerName, 'Unknown')AS VARCHAR(100)) AS BrokerIDName
 , CAST(ISNULL(dbo.VieClaimRegister.AssessorID,'None') + ' ' + ISNULL(dbo.MstClaimAssessors.AssesorID,'Unknown')AS VARCHAR(100)) AS AssessorIDName

意思是你需要这样的东西:

 , CAST(Cast(dbo.VieClaimRegister.AgentID as varchar(10)) + ' ' + ISNULL(dbo.MstAgent.AgentName, 'Unknown')AS VARCHAR(100)) AS AgentIDName 
 , CAST(Cast(dbo.VieTeamSelect.SubRegionID as varchar(10)) + ' ' + ISNULL(dbo.VieTeamSelect.SubRegionName, 'Unknown')AS VARCHAR(100)) AS SubRegionIDName
 , CAST(Cast(dbo.VieClaimRegister.TeamID as varchar(10)) + ' ' + ISNULL(dbo.VieTeamSelect.TeamName, 'Unknown')AS VARCHAR(100)) AS TeamIDName
 , CAST(Cast(dbo.VieClaimRegister.LinkID as varchar(10)) + ' ' + ISNULL(dbo.MstLink.LinkName, 'Unknown')AS VARCHAR(100)) AS LinkIDName
 , CAST(Cast(dbo.TrnPolicy.BrokerContact as varchar(10)) + ' ' + ISNULL(MstHandler.BrokerName, 'Unknown')AS VARCHAR(100)) AS BrokerIDName
 , CAST(ISNULL(Cast(dbo.VieClaimRegister.AssessorID as varchar(10)),'None') + ' ' + ISNULL(dbo.MstClaimAssessors.AssesorID,'Unknown')AS VARCHAR(100)) AS AssessorIDName

答案 1 :(得分:1)

当您想要将数字与varchar连接时,需要将数字转换为varchar,否则它会尝试将varchar转换为数字以使其成为一个补充。