MDX - Concatenate level's properties and level's members - properties

I an using mondrian and I have this issue: using a query mdx I need to concatenate in each member name belonging to a certain level, its name and a the value of a certain level properties for that member.
Something like CurrentMember.Name = CurrentMember.Name || CurrentMember.Properties("Prop").
Is this possible in some way?
Thanks.
Matteo

In MDX it should look like that
[Dimension].CurrentMember.Name + [Dimension].CurrentMember.Properties("YourProp")
The concatenation operator in MDX is + not ||

Related

How to find rows by filtering a specific text using Full text search in MS SQL 2012

I have a requirements to find rows by filtering a specific text using Full Text Search in MS SQL. The first requirement is to find rows by searching the text within the xml column, and the second requirement, is to find rows by searching the text within the json column(nvarchar data type). The following conditions should return a result.
XML Column
Criteria 1. Where Contains(XMLData,"1")
Criteria 2. Where Contains(XMLData,"/1/")
Criteria 3. Where Contains(XMLData,"<field>1</field>")
JSONDATA Column :
Criteria 1. Where Contains(JSONData,"1")
Criteria 2. Where Contains(JSONData,"/1/")
Criteria 2. Where Contains(JSONData,"PortalId:1")
My current implementation is by using the query below which has a performance issues when running thousand of records. Is there any other approach other than the code below?
XML QUERY
SELECT *
WHERE cast(XMLData as nvarchar(max)) LIKE '%/' + CONVERT(VARCHAR,'1') +'/%'
JSON QUERY
SELECT *
WHERE JSONDataLIKE '%/' + CONVERT(VARCHAR,'1') +'/%'
Here is a sample table for this question.
http://sqlfiddle.com/#!18/f65ef/1
I do not think that a full text search would help you. It seems you are looking for any fragment even such as technical terms like /1/.
Try this for XML
DECLARE #SearchFor VARCHAR(100)='1';
SELECT *
FROM SettingsData
WHERE xmldata.exist(N'//*[contains(text()[1],sql:variable("#SearchFor"))]')=1;
It will check any node's internal text() if it contains the search phrase. But any value with a 1 inside is found (e.g. any unrelated number which has a 1 somewhere.) You might search for text()="1" and perform the contains only if the string length exceeds a certain minimum.
Something like
WHERE xmldata.exist(N'//*[text()[1]=sql:variable("#SearchFor") or(string-length(text()[1])>=3 and contains(text()[1],concat("/",sql:variable("#SearchFor"),"/")))]')=1;
Json is - up to now - nothing more than a string and must be parsed. With v2016 Microsoft introduced JSON support, but you are on v2012. The problem with a LIKE search on a JSON-string might be, that you would find the 1 even as a part of an element's name. The rest is as above...
SELECT *
FROM SettingsData
WHERE jsondata LIKE '%' + #SearchFor + '%';

How to specify the thousands and decimals separators for the mdx query?

Currently if I run MDX queries I get the formatted values like
123.456.789,01
What I want to achieve is that (period) is used as a decimal separator and (comma) as a thousands separator.
Is there any way to specify the separators/culture globally for all queries?
FORMAT_STRING is the standard way of altering formats: https://msdn.microsoft.com/en-us/library/ms146084.aspx
It can be implemeted within an mdx script like this:
WITH [Measures].[aMeasureFormat] AS
[Measures].[aMeasure]
, FORMAT_STRING = "#,##0.0"
SELECT
{} ON 0,
[Measures].[aMeasureFormat] ON 1
FROM [yourCube];
too late but it is probably:, LANGUAGE=1034, FORMAT_STRING="$#,##0.00"
will set apropriate code page.

Why does OLEDB (or Access?) rewrite WHERE clause

I'm facing a strange situation where OledbDataAdapter rearranges the WHERE clause of my query, thus shuffling all parameters. In addition, it doesn't recognize one of the parameters used in the query. Here's how it goes:
A simple table with 4 columns (and infinite rows :)):
Name varchar(50)
Category varchar(20) //One of around 15-20 possible values
YR int //Year
Period int //Month
User will query this table using Year, Month and a comma-separated list of categories that he's interested in. Since .NET doesn't support multi-valued parameters through IN operator, what I do is to accept the list of categories as comma-separated list and then prepend and append a comma to this list within the query and use built-in INSTR() function to filter results for desired categories. User can also supply an empty string for categories filter in which case query will need to return all results (i.e. no filter on categories).
Therefore my query looks like this:
SELECT * FROM [Table1] WHERE
YR = ? AND
Period = ? AND
(LTRIM(RTRIM(?)) = '' OR INSTR(1, ?, ',' + Category + ',') > 0)
This worked with MDBs in the past. But recently I tried it against an ACCDB. The first thing I noted is that when I try to run the query in OledbDataAdapter wizard, Visual Studio rewrites it as:
SELECT * FROM [Table1] WHERE
(YR = ? AND Period = ? AND LTRIM(RTRIM(?)) = '') OR
(YR = ? AND Period = ? AND INSTR(1, ?, ',' + Category + ',') > 0)
In other words, it has rearranged the condition A AND B AND (C OR D) as (A AND B AND C) OR (A AND B AND D).
This would have been fine with me, but the additional problem is that this changes the number of parameters from 4 to 6; the query therefore doesn't return any results even when it should. Moreover, it doesn't recognize that last parameter (the question mark within INSTR function) at all.
So my questions are:
Who is rewriting the query (OledbDataAdapter, Access query parser or something else)?
Why is it doing so? Optimization? Apparently my version of the WHERE clause is more efficient.
Why doesn't it see the last parameter?
How to fix/workaround this issue? (plz do not suggest using 2 separate queries for it).

Pentaho Dynamic SQL queries

I have a Pentaho CDE project in development and i wanted to display a chart wich depends on several parameters (like month, year, precise date, country, etc). But when i want to "add" another parameter to my query, it doesn't work anymore... So i'm sure i'm doing something wrong but what ? Please take a look for the parameter month for example :
Select_months_query : (this is for my checkbox)
SELECT
"All" AS MONTH(TransactionDate)
UNION
SELECT DISTINCT MONTH(TransactionDate) FROM order ORDER BY MONTH(TransactionDate);
Select_barchart_query : (this is for my chart, don't mind the other tables)
SELECT pginit.Family, SUM(order.AmountEUR) AS SALES
FROM pginit INNER JOIN statg ON pginit.PG = statg.PGInit INNER JOIN order ON statg.StatGroup = order.StatGroup
WHERE (MONTH(order.TransactionDate) IN (${month}) OR "All" IN (${month}) OR ${month} IS NULL) AND
/*/* Apply the same pattern for another parameter (like year for example) *\*\
GROUP BY pginit.Family
ORDER BY SALES;
(Here, ${month} is a parameter in CDE)
Any ideas on how to do it ?
I read something there that said to use CASE clauses... But how ?
http://forums.pentaho.com/showthread.php?136969-Parametrized-SQL-clause-in-CDE&highlight=dynamic
Thank you for your help !
Try simplifying that query until it runs and returns something and work from there.
Here are some things I would look into as possible causes:
I think you need single quotes around ${parameter} expressions if they're strings;
"All" should probably be 'All' (single quotes instead of double quotes);
Avoid multi-line comments. I don't think you can have multi-line comments in CDE SQL queries, although -- for single line comments usually works.
Be careful with multi-valued parameters; they are passed as arrays, which CDA will convert into comma separated lists. Try with a single valued parameter, using = instead of IN.

Report Services Percentage calculation

I am trying to write an expression in SQL Reporting Services that evaluates 2 fields and works out the percentage value of one of them.
Basically:
Fields!Value.Value (numeric value) + Fields!StandardDuty.Value (% value)
An example of this would be (if keyed into a calculator)
39792.82(Fields!Value.Value ) + 2.7%(Fields!StandardDuty.Value ) = 1074.40614
Any help would be much appreciated
I think you just need to create your expression like this:
=Fields!yourFirstColumn.Value*(Fields!yourSecondColumn.Value/100)
I just tested this using the values, you provided above and returned 1074.40614