重複の可能性:
これら2つのSQLステートメントを組み合わせる方法は?
2つのSQLクエリがあります。CMSUID
それらは、変数がテーブルのいずれかまたは値に等しいことに基づいてカウントを取得CASUID
します。それ以外はまったく同じです。CASE
おそらくステートメントを使用して、それらを1つのクエリに組み合わせるにはどうすればよいですか。
select @cntCM_CNF = count(distinct(c.ID_Case))
from dbo.Cases c
join dbo.vew_CasePersonnelSystemIDs vcps on c.ID_Case = vcps.ID_Case
join hearings h on c.ID_Case = h.ID_Case
where vcps.CMSUID = @nSUID
and h.HearingDate > getdate()
and h.OnCalendar = 1 and h.Scheduled = 1
and dbo.fn_HearingConfirmedNoHOs(h.ID_Hearing) < 2
select @cntCC_CNF = count(distinct(c.ID_Case))
from dbo.Cases c
join dbo.vew_CasePersonnelSystemIDs vcps on c.ID_Case = vcps.ID_Case
join hearings h on c.ID_Case = h.ID_Case
where vcps.CASUID = @nSUID
and h.HearingDate > getdate()
and h.OnCalendar = 1 and h.Scheduled = 1
and dbo.fn_HearingConfirmedNoHOs(h.ID_Hearing) < 2
結果は個別のアイテムの数であるため、それらを組み合わせる方法がわかりません。それを実現する方法がわからない。