How to generate mdx query using C#
I am new to mdx query and i am very curious about mdx query generation using c# so i searched for any demo or open source then i found
Ranet.olap, which is providing what i need. After taking the dlls i tried to incorporate them in my code. I am pasting my full
console code which should generate mdx query but it's not doing so, Am i doing something wrong.
using System;
using System.Collections.Generic;
using Microsoft.AnalysisServices.AdomdClient;
using Ranet.Olap.Core.Managers;
using Ranet.Olap.Core.Metadata;
using Ranet.Olap.Core.Types;
namespace MDX
class Program
static void Main(string[] args)
startWork();
public static void startWork()
string connString = "Provider=MSOLAP.3; Data Source=localhost;Initial Catalog=AdventureWorkDW2008R2;Integrated Security=SSPI;";
CubeDef cubes;
AdomdConnection conn = new AdomdConnection(connString);
conn.Open();
cubes = conn.Cubes.Find("AdventureWorkCube");
Ranet.Olap.Core.Managers.MdxQueryBuilder mdx = new Ranet.Olap.Core.Managers.MdxQueryBuilder();
mdx.Cube = cubes.Caption;
List<Ranet.Olap.Core.Wrappers.AreaItemWrapper> listColumn = new List<Ranet.Olap.Core.Wrappers.AreaItemWrapper>();
List<Ranet.Olap.Core.Wrappers.AreaItemWrapper> listRow = new List<Ranet.Olap.Core.Wrappers.AreaItemWrapper>();
List<Ranet.Olap.Core.Wrappers.AreaItemWrapper> listData = new List<Ranet.Olap.Core.Wrappers.AreaItemWrapper>();
//Column area
Dimension dmColumn = cubes.Dimensions.Find("Dim Product");
Microsoft.AnalysisServices.AdomdClient.Hierarchy hColumn = dmColumn.Hierarchies["English Product Name"];
//hierarchy properties
List<PropertyInfo> lPropInfo = new List<PropertyInfo>();
foreach (var prop in hColumn.Properties)
PropertyInfo p = new PropertyInfo();
p.Name = prop.Name;
p.Value = prop.Value;
lPropInfo.Add(p);
Ranet.Olap.Core.Wrappers.AreaItemWrapper areaIColumn = new Ranet.Olap.Core.Wrappers.AreaItemWrapper();
areaIColumn.AreaItemType = AreaItemWrapperType.Hierarchy_AreaItemWrapper;
areaIColumn.Caption = hColumn.Caption;
areaIColumn.CustomProperties = lPropInfo;
listColumn.Add(areaIColumn);
//Rows Area
Dimension dmRow = cubes.Dimensions.Find("Due Date");
Microsoft.AnalysisServices.AdomdClient.Hierarchy hRow = dmRow.Hierarchies["English Month Name"];
List<PropertyInfo> lRowPropInfo = new List<PropertyInfo>();
foreach (var prop in hRow.Properties)
PropertyInfo p = new PropertyInfo(prop.Name,prop.Value);
lRowPropInfo.Add(p);
Ranet.Olap.Core.Wrappers.AreaItemWrapper areaIRow = new Ranet.Olap.Core.Wrappers.AreaItemWrapper();
areaIRow.AreaItemType = AreaItemWrapperType.Hierarchy_AreaItemWrapper;
areaIRow.Caption = hRow.Caption;
areaIRow.CustomProperties = lRowPropInfo;
listRow.Add(areaIRow);
//Measure Area or Data Area
Measure ms = cubes.Measures.Find("Order Quantity");
Ranet.Olap.Core.Wrappers.AreaItemWrapper areaIData = new Ranet.Olap.Core.Wrappers.AreaItemWrapper();
areaIData.AreaItemType = AreaItemWrapperType.Measure_AreaItemWrapper;
areaIData.Caption = ms.Caption;
List<PropertyInfo> lmpropInfo = new List<PropertyInfo>();
foreach (var prop in ms.Properties)
PropertyInfo p = new PropertyInfo(prop.Name, prop.Value);
lmpropInfo.Add(p);
areaIData.CustomProperties = lmpropInfo;
listData.Add(areaIData);
mdx.AreaWrappersColumns = listColumn;
mdx.AreaWrappersRows = listRow;
mdx.AreaWrappersData = listData;
string mdxQuery = mdx.GenerateMdxQuery();
conn.Close();
Hi mkm1,
According to your description, you want to use C# code to generate MDX Query. Right?
In Analysis Servcies, we just need to use "Microsoft.AnalysisServices.AdomdClient.dll" to open connection to SSAS database and retrieve data from cube. Here are some sample code about executing MDX query using C#.
Dim objConnection As New AdomdConnection("Data Source=localhost;Initial Catalog=Adventure Works DW 2008;")
Dim objCommand As New AdomdCommand()
Dim objDatatable As New DataTable
Dim strCommand As String
strCommand = "SELECT [Measures].[Internet Sales Amount] ON COLUMNS, "
strCommand = strCommand & " [Date].[Calendar].[Calendar Year] ON ROWS"
strCommand = strCommand & " FROM [Adventure Works]"
objConnection.Open()
objCommand.Connection = objConnection
objCommand.CommandText = strCommand
Dim objDataAdapter As New AdomdDataAdapter(objCommand)
objDataAdapter.Fill(objDatatable)
objConnection.Close()
Since your code is more related to a third party API, we suggest you post your question to Rnet.
Reference:
Microsoft.AnalysisServices.AdomdClient Namespace
If you have any question, please feel free to ask.
Simon Hou
TechNet Community Support
Similar Messages
-
How to generate addm report using grid
Hi,
how to generate addm report using grid, please provide any relevant doc/links etc.
Thanks in advance.how to generate addm report using grid, please provide any relevant doc/links etc.When you start with the wrong question, no matter how good an answer you get, it won't matter very much.
what is best way to divide board into 2 pieces using a hammer?
Edited by: sb92075 on Oct 25, 2010 7:22 AM -
How to generate multiple sheets using xml publisher
Hi,
how to generate multiple sheets using xml publisher.
Thanks,
Nurhttp://lmgtfy.com/?q=how+to+generate+multiple+sheets+using+xml+publisher
-
How to generate Webservices.xml using tool in Sun One App Server?
How to generate Webservices.xml using tool in Sun One App Server?
Hi,
The build.xml file should be in a directory from where
you are running the asant command.
To resolve the common.xml file not found error,
open your build.xml and check from which location the common.xml file is incuded.
In the sample application it is four directories above
the directory where build.xml is located.
You can copy the common.xml in the current directory and then change the following in your build.xml
<!ENTITY include SYSTEM "../../../../common.xml">
to <!ENTITY include SYSTEM "common.xml">
Hope this helps.
Get back in case you have more issues -
How to generate pwm pulse using NI DAQ in MATLAB
hi everyone. please tell me how to generate pwm pulses using Ni DAQ card in MATLAB Simulink. if through coding is possible then post the corresponding code.....reply me
Make sure you have installed the Measurement studio support for VB 6.0 then you will be able to find examples in the folder below on win7 and 8.
C:\Users\Public\Documents\National Instruments\NI-DAQ\Examples
Narrow down to Analog Output and choose update voltage example for measurement studio.
You also have the possibility to use DAQ assistant if you have measurement studio installed. This function is a configuration type programming. After going through the configuration Wizard code is automatically scripted for you so that you can output the voltage you need. Read more about DAQ assistant in the blow link.
http://www.ni.com/white-paper/4652/en/
Best Regards
Jonas Mäki
Applications Engineering
National Instruments -
Excel Generating MDX Query With Crossjoins
Hi All,
I am having performance issues while using excel to browse SSAS cube.
I ran the pro filer and captured the MDX queries and query which excel has auto generated has lot of cross joins
All i am doing is selecting 3 attributes in a dimension and i can't understand why excel is choosing to use cross joins
Can any one please give me some options on how to make excel not use cross joins ?
Query From BIDS :
SELECT NON EMPTY { } ON COLUMNS, NON EMPTY { ([Orders].[Order No].[Order No].ALLMEMBERS * [Orders].[Order Status].[Order Status].ALLMEMBERS * [Orders].[Branch].[Branch].ALLMEMBERS ) } DIMENSION PROPERTIES MEMBER_CAPTION, MEMBER_UNIQUE_NAME ON ROWS FROM [Sales_Detail]
CELL PROPERTIES VALUE
Query From Excel :
SELECT
NON EMPTY CrossJoin(CrossJoin(Hierarchize({DrilldownLevel({[Orders].[Order No].[All]},,,INCLUDE_CALC_MEMBERS)}), Hierarchize({DrilldownLevel({[Orders].[Order Status].[All]},,,INCLUDE_CALC_MEMBERS)})), Hierarchize({DrilldownLevel({[Orders].[Branch].[All]},,,INCLUDE_CALC_MEMBERS)}))
DIMENSION PROPERTIES PARENT_UNIQUE_NAME,HIERARCHY_UNIQUE_NAME,[Orders].[Order No].[Order No].[Branch],[Orders].[Order No].[Order No].[Legal Entity],[Orders].[Order No].[Order No].[Likelihood Of Deal],[Orders].[Order No].[Order No].[Order Status],[Orders].[Order
No].[Order No].[Order Type],[Orders].[Order No].[Order No].[Products ID] ON COLUMNS FROM [Sales_Detail] CELL PROPERTIES VALUE, FORMAT_STRING, LANGUAGE, BACK_COLOR, FORE_COLOR, FONT_FLAGSHi Satish,
According to your description, you find Excel using a lot of CROSSJOIN when driving data from cube. It caused bad performance and you want to avoid it. Right?
This is a known issue in Excel, it uses a certain template to build the cross join. It uses DrillDown.... functions for complex user filter selection when doing drill down. It's the default behavior of Excel and it hasn't been fixed yet.
In this scenario, I suggest you build user hierarchy in your cube and use it in Excel when retrieving data into pivot table.
See a similar thread below:
https://social.msdn.microsoft.com/forums/sqlserver/en-US/99a6a97f-518a-4fe6-b9bd-fa81f0a44587/controlling-the-mdx-constructed-by-excel-pivottables
Reference:
Binding an Excel table to the results of an MDX query
Best Regards,
Simon Hou
TechNet Community Support -
Hi,
I have created a WEBI report on an OLAP universe on top of a BEx query. Is it possible to see the MDX query being generated by my WEBI report? If yes, then could someone please guide me as to how do I see the exact MDX query generated by the report? Thanks!
Regards,
- Noman JafferyHi Ingo,
Thanks for the answer. We are having an issue and I was wondering if you could shed somelight on this.
Our WEBI report running on top of an OLAP Universe on BEx query is taking forever to run and in the end does not return any data.
We are monitoring the query through BW and apparently it is stuck in the step: CL_RSR_MDX_BXML_FLATTENING.
Through logging we got the underlying MDX query and ran it in BEx Editor and it ran in seconds. But when the same MDX query in ran in BEx Editor using the XML option, it is stucking on the same step i.e. CL_RSR_MDX_BXML_FLATTENING
My hunch is that the result is being converted into XML format from MDX native format before it is passed on to InfoView and this conversion/flattening is taking forever. Is it a known issue? Is there any way around? Thanks!
- Noman Jaffery -
Simple sql to mdx query using the max fn
I'm using the MDX Max fn to get the max of a certain value but now I want get max for a certain pair of values and not all, how could i write this in mdx as a calculation?
More details: For a certain pair of status and substatus (status=1, substatus=1) from a trans dimension table i want to get the max insertionid (attribute in trans measure table). How would you guys suggest I go about this?
I'm new to mdx and I'm converting a whole sql statement to a measure not to include it as a named query for performance concerns!
If needed this is the sql query im converting:
SELECT TOP (1) InsertionDT
FROM dbo.TransTasksFFMS_GVT AS TSI
WHERE (TaskCode = T.TaskCode) AND (TaskStatus = 1) AND (TaskSubStatus = 1)
ORDER BY InsertionDT) AS RegistrationTimeWithoutConversion
Another way to think of this is how to apply a certain measure only on certain values and not all values in the browser.Hi Junior,
According to your description, you want to get the max value by using MDX query, right? Since no know your cube detail information, we cannot convert this T-SQL to MDX query. Here is a sample MDX query for your reference. The query below returns the Sale
Amount measure and the MaxValue calculated member. The MaxValue calculated member takes the maximum value for members of the Fiscal Year level in the Fiscal hierarchy of the Date dimension.
WITH
MEMBER [Measures].[MaxValue] AS
MAX([Date].[Fiscal].[Fiscal Year].Members, [Measures].[Sales Amount])
SELECT
{[Measures].[Sales Amount],[Measures].[MaxValue]} ON COLUMNS,
{[Date].[Fiscal].[Fiscal Year].Members} ON ROWS
FROM
[Adventure Works]
Reference:Max (MDX)
Regards,
Charlie Liao
TechNet Community Support -
How to convert MDX query to SQL
Hi everyone,
can you please suggest me, how to convert the below mdx query to sql query. can you please tell me what it is doing?
CREATE MEMBER CURRENTCUBE.[Measures].[calculation]
AS IIF(([Measures].[Clear Call Count],[Trouble Code].[Is Battery].&[Battery T-Code],[Service Provider].[Is Towmark].&[Towmark],[Provider Technician].[Is Towmark].&[Towmark]) = 0, NULL,
([Measures].[ Total Shipped],[Service Provider].[Is Towmark].&[Towmark],[Provider Technician].[Is Towmark].&[Towmark])/
([Measures].[Clear Call Count],[Trouble Code].[Is Battery].&[Battery T-Code],[Service Provider].[Is Towmark].&[Towmark],[Provider Technician].[Is Towmark].&[Towmark])),
FORMAT_STRING = "Percent",
VISIBLE = 1 , ASSOCIATED_MEASURE_GROUP = 'Sale';
Thanks
VishuHi Vishu,
As Olaf said, this is a calculated member which used in MDX script in your cube, we cannot execute it in SQL Server Management Studio directly. Here are some document about calculated members and MDX script for your reference.
Defining Calculated Members
MDX Scripting Fundamentals (Analysis Services)
Regards,
Charlie Liao
TechNet Community Support -
How to generate a query automatically?
Hello,
I set up a PreparedStatment pstmt = conn.prepareStatment(" select distinct ? from table ")
and then
pstmt.setString(1, "country")
and I use ResultSet rs = pstmt.executeQuery()
but the result is not what I expect.. It only returns "country"
if I change it to stmt = conn.createStatement("select distinct country from table")
it works
So, how can I generate a query like this automatically?
Thanks!The query you posted means "return the first argument once for every row in the table called 'table'." What is it you are trying to do?
And, you may want to post this on the JDBC forum rather than here. -
How to make dynamic query using DBMS_SQL variable column names
First of all i will show a working example of what i intend to do with "EXECUTE IMMEDIATE":
(EXECUTE IMMEDIATE has 32654 Bytes limit, which isn't enough for me so i'm exploring other methods such as DBMS_SQL)
-------------------------------------------------CODE-----------------------------------
create or replace PROCEDURE get_dinamic_query_content
(query_sql IN VARCHAR2, --any valid sql query ('SELECT name, age FROM table')
list_fields IN VARCHAR2) --list of the columns name belonging to the query ( arr_list(1):='name'; arr_list(2):='age';
-- FOR k IN 1..arr_list.count LOOP
-- list_fields := list_fields || '||content.'||arr_list(k)||'||'||'''~cs~'''; )
AS
sql_stmt varchar (30000);
BEGIN
sql_stmt :=
'DECLARE
counter NUMBER:=0;
auxcontent VARCHAR2(30000);
CURSOR content_cursor IS '|| query_sql ||';
content content_cursor%rowtype;
Begin
open content_cursor;
loop
fetch content_cursor into content;
exit when content_cursor%notfound;
begin
auxcontent := auxcontent || '||list_fields||';
end;
counter:=counter+1;
end loop;
close content_cursor;
htp.prn(auxcontent);
END;';
EXECUTE IMMEDIATE sql_stmt;
END;
-------------------------------------------------CODE-----------------------------------
I'm attepting to use DBMS_SQL to perform similar instructions.
Is it possible?Hi Pedro
You need to use DBMS_SQL here because you don't know how many columns your query is going to have before runtime. There are functions in DBMS_SQL to get information about the columns in your query - all this does is get the name.
SQL> CREATE OR REPLACE PROCEDURE get_query_cols(query_in IN VARCHAR2) AS
2 cur PLS_INTEGER;
3 numcols NUMBER;
4 col_desc_table dbms_sql.desc_tab;
5 BEGIN
6 cur := dbms_sql.open_cursor;
7 dbms_sql.parse(cur
8 ,query_in
9 ,dbms_sql.native);
10 dbms_sql.describe_columns(cur
11 ,numcols
12 ,col_desc_table);
13 FOR ix IN col_desc_table.FIRST .. col_desc_table.LAST LOOP
14 dbms_output.put_line('Column ' || ix || ' is ' ||
15 col_desc_table(ix).col_name);
16 END LOOP;
17 dbms_sql.close_cursor(cur);
18 END;
19 /
Procedure created.
SQL> exec get_query_cols('SELECT * FROM DUAL');
Column 1 is DUMMY
PL/SQL procedure successfully completed.
SQL> exec get_query_cols('SELECT table_name, num_rows FROM user_tables');
Column 1 is TABLE_NAME
Column 2 is NUM_ROWS
PL/SQL procedure successfully completed.
SQL> exec get_query_cols('SELECT column_name, data_type, low_value, high_value FROM user_tab_cols');
Column 1 is COLUMN_NAME
Column 2 is DATA_TYPE
Column 3 is LOW_VALUE
Column 4 is HIGH_VALUE
PL/SQL procedure successfully completed.I've just written this as a procedure that prints out the column names using dbms_output - I guess you're going to do something different with the result - maybe returning a collection, which you'll then parse through in Apex and print the output on the screen - this is just to illustrate the use of dbms_sql.
best regards
Andrew
UK -
How to generate localized chars using code point in Solaris 10?
Hi All,
Do enybody know how to generate localized chars (for example Japanese) using code points in Solaris 10?
Like in the following web page:
http://www.isthisthingon.org/unicode/index.phtml
Unicode, shift-jis
U+4e2f 87a3 �N
U+4e3b 8ee5 ��
U+4e3c 98a5 �S
U+4f5c 8dec ��
Thanks,
DanielI have found a "Code Point Input Method" tool in the following page:
http://java.sun.com/products/jfc/tsc/articles/InputMethod/inputmethod.html
Using this tool user can enter hexadecimal code point and the output is some char.
But this tool doesn't work. I run this in the follwoing way:
# java -jar CodePointIM.jar
After this error message appers:
Failed to load Main-Class manifest attribute from
codepointim.jar
If anybody could help I will be appreciate.
Regards,
Daniel -
How to generate Java source using clientgen WL8.1?
Hi, does anybody know how to generate Java source code using clientgen task on WL 8.1 Sp4 or SP5? I know WL 9.0 clientgen can do this, but we are still on SP5. Basically I want to look at the source code (I was wondering why it didn't work if I initialize a service impl by passing the WSDL URL string different than the URL specified in the original WSDL file that the clientgen is run against.)
Does anybody also know how get web service client developed on Axis work on WebLogic without conficting the web service developed on WebLgoic that is running in the same box?
Thanks for your help!hi ,
As mentioned in the Question, I am unable to find the "Java Proxy Generattion" link in the Int builder.
Also the help doc says:
Java proxy generation is no longer supported in subsequent releases. For new developments or when making significant changes to a service interface, use Java proxy generation in SAP NetWeaver Studio instead. More information: Creating Outside-In Web Services, SAP NetWeaver Developer Studio.
Does that mean that I can no longer generate java proxy from Int builder?
regards,
Piyush -
How to generate DBMS_RANDOM Timestamp using procedure
Hi,
I got a copy from askTom site for the store procedure of creating random numbers in a table:
create or replace procedure clone( p_tname in
varchar2, p_records in number )
authid current_user
as
l_insert long;
l_rows number default 0;
begin
execute immediate 'create table clone_' || p_tname ||
' as select * from ' || p_tname ||
' where 1=0';
l_insert := 'insert into clone_' || p_tname ||
' select ';
for x in ( select data_type, data_length,
rpad( '9',data_precision,'9')/power(10,data_scale) maxval
from user_tab_columns
where table_name = 'CLONE_' || upper(p_tname)
order by column_id )
loop
if ( x.data_type in ('NUMBER', 'FLOAT' ))
then
l_insert := l_insert || 'dbms_random.value(1,' || x.maxval ||
elsif ( x.data_type = 'DATE' )
then
l_insert := l_insert ||
'sysdate+dbms_random.value+dbms_random.value(1,1000),';
else
l_insert := l_insert || 'dbms_random.string(''A'',' ||
x.data_length || '),';
end if;
end loop;
l_insert := rtrim(l_insert,',') ||
' from all_objects where rownum <= :n';
loop
execute immediate l_insert using p_records - l_rows;
l_rows := l_rows + sql%rowcount;
exit when ( l_rows >= p_records );
end loop;
end;
Can somebody tell me how to generate a random TIMESTAMP?
I try to change "sysdate" to systimestamp" and it give me an error:
ERROR at line 1:
ORA-01841: (full) year must be between -4713 and +9999, and not be 0
Please help!!
Message was edited by:
eecow
Message was edited by:
eecow
nullCan you give me an example of doing this?
The other question is:
Can the store procedure code (above) check other things other than data type?
For example:
if attributeName = 'percentage' --> create a random number from 0 to 100
The reason is because I am trying to generate some more "realistic" data. Some fields can be unrelistic, but fields like "percentage" should be within 0-100 and should not have something like 200 :)
Please advise.
Thanks! -
How to find sql query using sqlid
Hi
I am not aware of that sqlid .DBA is saying a particular sqlid is making problem .how to find the particular sql query using sql_id ?Are you aware of modplsql when i executed the query the result is like
DECLARE
rc__ NUMBER;
simple_list__ OWA_UTIL.vc_arr;
complex_list__ OWA_UTIL.vc_arr;
BEGIN
OWA.init_cgi_env (:n__, :nm__, :v__);
HTP.htbuf_len := 84;
NULL;
NULL;
simple_list__ (1) := 'sys.%';
simple_list__ (2) := 'dbms\_%';
simple_list__ (3) := 'utl\_%';
simple_list__ (4) := 'owa\_%';
simple_list__ (5) := 'owa.%';
simple_list__ (6) := 'htp.%';
simple_list__ (7) := 'htf.%';
simple_list__ (8) := 'wpg_docload.%';
IF ((owa_match.match_pattern ('Oly_browse.oly_pattern ',
simple_list__,
complex_list__,
TRUE
THEN
rc__ := 2;
ELSE
NULL;
NULL;
oly_browse.oly_pattern (search_phrase => :search_phrase, --Oly_browse.oly_pattern is package name
btn => :btn,
p_qual => :p_qual,
p_bcat => :p_bcat,
p_stdy => :p_stdy,
p_bloc => :p_bloc,
z => :z
IF (WPG_DOCLOAD.is_file_download)
THEN
rc__ := 1;
WPG_DOCLOAD.get_download_file (:doc_info);
NULL;
NULL;
NULL;
COMMIT;
ELSE
rc__ := 0;
NULL;
NULL;
NULL;
COMMIT;
OWA.get_page (:data__, :ndata__);
END IF;
END IF;
:rc__ := rc__;
END; Edited by: vishnu prakash on Sep 8, 2010 10:16 PM
Maybe you are looking for
-
I have an ipod touch and am trying to update ios to 5.1 from 4.2.1. When I connect to itunes, it says it is up to date but it is not. How do I update?
-
Why is my ipad2 really slow after updating to IOS 6.1.2
Why is my ipad2 really slow after updating to IOS 6.1.2
-
UDF Using Dynamic Configuration for Counter Reset
Hi All, In an Idoc to file scenario we want to have counter option at the end of the file.we are using NFS so that we wil not face any problem of counter reset on a j2ee restart But when the counter turns 999999 it has to be reset to 0000001 So we ar
-
Web template - No precalculated data found
I'm trying to precalculate the data in a web template using reporting agent. It is a template with only one data provider that does not require a control query... the input variable screen values can be stored in a variant so it is pretty straightfo
-
I need to purchase an app. Can I delete my card details straight after.
I need to purchase an app for my grandson. Can I delete my card details as soon as I have purchased the app.