我有一堆WITH
陈述:
;with OneAccession as (
select client_id,COUNT(patient_id) PatientCount from
(
select client_id,patient_id
from F_ACCESSION_DAILY
group by CLIENT_ID,PATIENT_ID
having COUNT(ACCESSION_ID)=1
) a
group by CLIENT_ID
)
,
TwoAccessions as (
select client_id,COUNT(patient_id) PatientCount from
(
select client_id,patient_id
from F_ACCESSION_DAILY
group by CLIENT_ID,PATIENT_ID
having COUNT(ACCESSION_ID)=2
) a
group by client_id
)
,
ThreeAccessions as (
select client_id,COUNT(patient_id) PatientCount from
(
select client_id,patient_id
from F_ACCESSION_DAILY
group by CLIENT_ID,PATIENT_ID
having COUNT(ACCESSION_ID)=3
) a
group by client_id
)
etc
我加入这些声明
select * from myTable
join OneAccession
on...
join TwoACcessions
on...
join ThreeAccessions
with
我可以创建一个存储过程,而不是拥有所有这些语句吗?我只是传递值having count(accession_id)=**@myParam**
并执行以下操作:
select * from myTable
join storedproc(1)
on...
join storedproc(2)
on...
etc...
加入存储的 Proc 是否有问题?我的方法可以吗?