0

クエリ全体を実行すると、次のエラー メッセージが表示されます。

------------------------------------
--POPULATE SECTIONAAVGTAT-----------
------------------------------------
;with SpecimenDetail as (
select
s.*
,a.[mlis id]
,a.director
,a.rm
,a.rep
,a.css
,a.css2
,dbo.networkdays(s.[date received],GETDATE())-1 [Days On Hold]
,(case when dbo.networkdays(s.[date received],GETDATE())-1>=7 then '7+' 
   when dbo.networkdays(s.[date received],GETDATE())-1 in (5,6) then '5-6'
   when dbo.networkdays(s.[date received],GETDATE())-1 in (3,4) then '3-4'
   when dbo.networkdays(s.[date received],GETDATE())-1 in (1,2) then '1-2'
   when dbo.networkdays(s.[date received],GETDATE())-1=0 then '0'
  else 'na'
end) as [Days on Hold Group]
 from specimendetailtmp s
left join sectionaalignment a
on s.[mlis practice id]=a.[mlis id]
where s.[date distributed] is not null
and s.[date received]>='20121112'
and s.sectiona='not marked'
)


,

AvgTAT as
(
select 'director' emptype,director employee, cast(round(AVG(cast (dbo.networkdays(s.[date received],s.[date distributed])-1  as float)), 3, 1) as decimal(10,1)) AvgTAT,month(s.[date received]) month from SpecimenDetail s
where s.[date distributed] is not null
group by director,month(s.[date received])


union all

select 'rm' emptype,rm employee, cast(round(AVG(cast (dbo.networkdays(s.[date received],s.[date distributed])-1  as float)), 3, 1) as decimal(10,1))AvgTAT,month(s.[date received]) month from SpecimenDetail s
where s.[date distributed] is not null
group by rm,month(s.[date received])

union all

select 'rep' emptype,rep employee,cast(round(AVG(cast (dbo.networkdays(s.[date received],s.[date distributed])-1 as float)), 3, 1) as decimal(10,1)) AvgTAT,month(s.[date received]) month from SpecimenDetail s
where s.[date distributed] is not null
group by rep,month(s.[date received])

union all

select 'css' emptype,css employee,cast(round(AVG(cast (dbo.networkdays(s.[date received],s.[date distributed])-1  as float)), 3, 1) as decimal(10,1)) AvgTAT,month(s.[date received]) month from SpecimenDetail s
where s.[date distributed] is not null
group by css,month(s.[date received])

union all

select 'css2' emptype,css2 employee,cast(round(AVG(cast (dbo.networkdays(s.[date received],s.[date distributed])-1  as float)), 3, 1) as decimal(10,1)) AvgTAT,month(s.[date received]) month from SpecimenDetail s
where s.[date distributed] is not null
group by css2,month(s.[date received])
)

select * from avgtat

ただし、内部選択のいずれかを実行すると、すべて正常に動作します!

スクリプト全体を実行したときにのみこのエラーが発生するのはなぜですか?

4

1 に答える 1

2

セグメント内の 1 つ以上のSELECT句が、UNION ALL暗黙的に に変換される結果を生成していると思われintます。また、他のSELECT句は次の結果を返しますnvarchar。結果の列の値がすべて整数の場合、暗黙的な変換が発生する可能性があります。

問題の原因となっている列がわからない場合は、それぞれの結果を確認しSELECT、共通のパターン (nvarchar 列ではすべての値が整数であるなど) があるかどうかを判断する必要があります。問題がある場合は、CASTまたはCONVERTを使用して値を目的のデータ型に明示的にキャストします。

于 2013-01-02T23:44:19.290 に答える