我有以下查詢,我想計算總行數爲@TotalRows
。查找與訂單的選擇查詢的總行數由
Declare @TotalRows int
@TotalRows = Count(Select distinct
a.id as apptID, i.Insurancename, InsDtl.Insurenceclassification
From
Appointment A
Left Outer join
Insuarancedetails InsDtl WITH (NOLOCK) on InsDtl.AppId = A.ID
Left Outer join
Insurance i WITH (NOLOCK) on i.ID = InsDtl.Insurencepayer
order by
apptID, Insurancename)
我試圖與Count(*)
和Row_Number()
但它不是wotking。它表示子查詢不允許使用order by子句。
你能告訴我的結果應該如何看起來像 –
我只需要計數,並在一個聲明變量中設置該計數。 – Hitesh
select @ TotalRows = count(*)from(your query here)T – nazark