我有一个产品表,我需要知道表中的记录数。目标是将返回查询分为 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