案例陈述中的SQL错误

时间:2018-01-23 05:14:50

标签: mysql compiler-errors type-conversion case

我需要以下案例陈述的帮助:

Select Distinct Case
Case When convert(int, cd.location) = 'H ' Then ''
     When convert(int, cd.location) = 'U8' Then ''
     When convert(int, cd.location) = 'A ' Then ''
     When convert(int, cd.location) = 'OH'   Then ''
End as LocationCleanup

问题是4个值(' H',' U8',' A'' OH')是数据类型varchar(10)显然包含一个非数字字符,因此,它们不能转换为int(我认为)。另外,cd.location数据类型是int。我更喜欢列LocationCleanup,不存在。我拥有它的唯一原因是尝试解决上一个案例声明之后的问题。

Case when c.formtype = '1500' and cd.location = 21 and ps.specialtycode in ('05','22','1T','1F','30','1C') then '04-Hospitalist'
    when c.formtype = '1500' then '04-Other'
    else '  '
End as DHHClaimtype,
Into ActualTable
From AnotherActualTable
Join a lot of stuff

我收到错误:转换varchar值时转换失败' H'到数据类型int。当我放下桌子并重新运行查询以进行故障排除时,错误存在于哪个值上似乎是随机的(' H',' U8',' A',' OH')。对于这4个值,我希望它们返回空白(''),因为这些是用户输入的数据错误。

我没想到什么?

如果有帮助,这是整个查询:

declare @start date = '06/01/2016';
declare @end date   = '07/31/2017';

-----------------------------------------------------------------------------    ------------------------------------------------
-- Pull all claims with paid date in range parameter
-----------------------------------------------------------------------------    
------------------------------------------------

if object_id('LA_Temp.dbo.Item19') is not null drop table LA_Temp.dbo.Item19
select distinct
c.claimid,  
c.formtype,
c.facilitycode + c.billclasscode as BillType, 
case when primaryclaimid = '' and resubclaimid = '' then 'Clean' else 'Other' end as CleanClaim,
    -- DHHClaimtype 04 needs to be broken out based on provider specialty and location
    Case when c.formtype = '1500' and cd.location = 21 and ps.specialtycode in ('05','22','1T','1F','30','1C') then '04-Hospitalist'
    when c.formtype = '1500' then '04-Other'
    else '  '
end as DHHClaimtype,
c.status,
c.totalpaid, 
e.phystate as MemberState,
e.phycounty as MemberParish,
pc.ParishCode as MemberParishCode,
con.contracted as NetworkProvider,
reject
into LA_Temp.dbo.Item19
from claim c
inner join member m on c.memid = m.memid
inner join entity e on m.entityid = e.entid
left join LA_Temp.dbo.ParishCodes pc on e.phycounty = pc.Parish
inner join contract con on c.contractid = con.contractid
inner join provider p on c.provid = p.provid
inner join provspecialty ps on p.provid = ps.provid and ps.spectype = 
'PRIMARY'
inner join claimdetail cd on c.claimid = cd.claimid and cd.claimline = 1 and 
cd.location not in ('OH', 'A ', 'U8', 'H ') -- just pull the first line to 
grab the location code, exclude any location codes with non-numeric values
where c.paiddate between @start and @end
and c.status in ('PAID','DENIED');

-- add the claim types to the table
EXECUTE LA_Temp.[dbo].[USP_LA_SetDHHClaimType] @Table = 'Item19';

先谢谢你们。

0 个答案:

没有答案