0
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 查询,用于访问一组用于报告服务的数据。但是,它给了我一个错误“将 varchar 值 'Absa Insurance and Financial Advisers (Pty) Limited' 转换为数据类型 int 时转换失败。” 即使在将所有内容都转换为 Varchar 之后。我对 SQL 还是很陌生,因此我们将不胜感激任何帮助。抱歉,它这么长,有很多数据需要处理。

4

2 回答 2

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
于 2013-10-07T09:56:49.547 回答
1

当您想将数字与 varchar 连接时,您需要将数字转换为 varchar,否则它将尝试将 varchar 转换为数字以使其成为加法。

于 2013-10-07T09:59:58.297 回答