How to get top 10 records from below query? This query is throwing Out of Memory exception.
SELECT
[Build].[Build ID] ON 0
,
[Build].[Build Definition Name].MEMBERS*
[Build].[Build].MEMBERS*
[Build].[Build Start Time].MEMBERS*
[Build Status].[Build Status] ON 1
FROM Build
This is exactly the same as Sourav's answer but slightly simpler without the creation of the custom set:
SELECT
[Build].[Build ID] ON 0
,TopCount
(
[Build].[Build Definition Name].MEMBERS*
[Build].[Build].MEMBERS*
[Build].[Build Start Time].MEMBERS*
[Build Status].[Build Status]
,10
) ON 1
FROM Build;
I've just tested against AdvWrks
as I'm interested in your error message.
This script takes 11 seconds on my machine with a warm cache:
SELECT [Measures].[Internet Order Quantity] ON 0,
NON EMPTY
[Date].[Date].MEMBERS
*
[Product].[Subcategory].MEMBERS
*
[Geography].[Country].MEMBERS
*
[Customer].[Gender].MEMBERS
ON 1
FROM
[Adventure Works]
Whereas this is instantaneous:
SELECT [Measures].[Internet Order Quantity] ON 0,
NON EMPTY
TOPCOUNT(
[Date].[Date].MEMBERS
*
[Product].[Subcategory].MEMBERS
*
[Geography].[Country].MEMBERS
*
[Customer].[Gender].MEMBERS
, 10
)
ON 1
FROM
[Adventure Works]
Your error is probably because it is trying to return and render a very big table in your results panel.
As per MSDN , you get the top-N values using TOPCOUNT
function, whose definition is
TopCount(Set_Expression,Count [ ,Numeric_Expression ] )
You want the top 10 based on what? In absense of any measure, it will get you the top 10 based on the default measure.
WITH SET TOP10BuildID
AS
TopCount(([Build].[Build ID].MEMBERS*
[Build].[Build Definition Name].MEMBERS*
[Build].[Build].MEMBERS*
[Build].[Build Start Time].MEMBERS*
[Build Status].[Build Status]),10)
SELECT
TOP10BuildID ON 0
[Measures].SomeMeasure
ON 1
FROM [Build]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.