製品テーブルがあり、テーブル内のレコード数を知る必要があります。目標は、リターン クエリを 2 つの個別のクエリに分割することです。
If (Count(*) % 2) = 0 return top(Count(*) / 2)
else return top((Count(*) / 2) + 1)
主なクエリは次のとおりです。
select coalesce(Price, ProductPrice) as Price, Product.ProductName, Customer.CustomerName, Product.CatalogNum from Product
inner join Customer on CustomerID = @custId
left outer join CustomerPrice on dbo.Customer.CustomerID = dbo.CustomerPrice.CustomerID
and dbo.Product.ProductID = dbo.CustomerPrice.ProductID
Where Product.ProductActive = 1 Order by Product.CatalogNum