我正在修改用于提取SSIS包中的数据的查询。它由3个并集组成,所有先前的子查询都可以正常工作,但是最后一个查询返回“将datetimeoffset数据类型转换为datetime数据类型,导致值超出范围”错误。我认为这可能是由于PolicyExpirationDate字段包含空值(对于尚未过期的策略)。我尝试应用我在工会的其他子查询中所做的工作,但是没有运气。
这里是返回错误的子查询(连同我注释掉的尝试修复错误的信息):
select DISTINCT
P.PolicyNumber
,S.RatingPeriod 'RatingPeriodNumber'
, 'VES' as 'RatingPeriodSource'
,P.Id 'PcmPolicyId'
,CONVERT(datetime,P.PolicyEffectiveDate) AS PolicyEffectiveDate
,CONVERT(datetime,P.PolicyExpirationDate) AS PolicyExpirationDate
--, ISNULL(CONVERT(datetime,P.PolicyExpirationDate),'2030-12-31') AS PolicyExpirationDate
--CONVERT(datetime, '2010-07-25T13:50:38.544', 126) AS PolicyExpirationDate
--,CONVERT(datetime, P.PolicyExpirationDate, 126) AS PolicyExpirationDate
, 'Coverage' as 'Level'
, pcsf.Name 'Factor_Name'
, pcsf.value 'Factor_Amount'
,(select max(s2.Id) from PolicyStatus S2 where s.PolicyId = s2.PolicyId and s.RatingPeriod = s2.RatingPeriod) 'PS_PolicyTransID'
,CONVERT(datetime,(select max(s2.EffectiveDate) from PolicyStatus S2 where s.PolicyId = s2.PolicyId and s.RatingPeriod = s2.RatingPeriod)) 'ActivationDate'
from
policy p
inner JOIN PolicyStatus s ON s.PolicyId = P.Id
inner join policyschema ps on ps.policyid = p.id --get schema used on the policy
left outer join policyschemacoveragecontainer pscc on pscc.SchemaId = ps.id --get coverage level factors
left outer join policyschemacoverage psc on psc.containerid = pscc.id
left outer join policycoverageschemafactor pcsf on pcsf.coverageid = psc.id and pcsf.IsSelected = 1
where pcsf.Name not like 'Minimum Monthly Premium'