私はたくさんの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...
ストアドプロシージャへの参加に問題はありますか?私の方法論は大丈夫ですか?