Writing Case in MDX query? - ssas

I have an MDX code like this,
({[Ping].[ID].&[20] : [Ping].[ID].&[200]})
.
.
I have to write it with the use of Switch/Case statement.
This is what I done, but something is missing, not working.
WITH MEMBER [Ping].[ID].[FORMAT2] AS
CASE
WHEN [Ping].[ID].&[10]
THEN [Ping].[ID].&[100]
WHEN [Ping].[ID].&[20]
THEN [Ping].[ID].&[200]
ELSE [Ping].[ID].[FORMAT]
END
Please help me.

WHEN [Ping].[ID].&[10]
is not a condition. The WHEN statements inside a case need to be a condition that evaluates to true or false.
Something like
WHEN [Ping].[ID].CurrentMember IS [Ping].[ID].&[10]
or something similar.

Related

Unable to query using 4 conditions with WHERE clause

I am trying to query a database to obtain rows that matches 4 conditions.
The code I'm using is the following:
$result = db_query("SELECT * FROM transportesgeneral WHERE CiudadOrigen LIKE '$origen%' AND DepartamentoOrigen LIKE '$origendep' AND DepartamentoDestino LIKE '$destinodep' AND CiudadDestino LIKE '$destino%'");
But it is not working; Nevertheless, when I try it using only 3 conditions; ie:
$result = db_query("SELECT * FROM transportesgeneral WHERE CiudadOrigen LIKE '$origen%' AND DepartamentoOrigen LIKE '$origendep' AND DepartamentoDestino LIKE '$destinodep'");
It does work. Any idea what I'm doing wrong? Or is it not possible at all?
Thank you so much for your clarification smozgur.
Apparently this was the problem:
I was trying to query the database by using the word that contained a tittle "Petén" so I changed the database info and replaced that word to the same one without the tittle "Peten" and it worked.
Now, im not sure why it does not accept the tittle but that was the problem.
If you have any ideas on how I can use the tittle, I would appreciate that very much.

Mule ESB: How to do Condition checking in Datamapper using Xpath

i'm facing issue in xpath-I need do a check two attribute values, if the condition satisfies need to do hard code my own value. Below is my xml.
I need to check the condition like inside subroot- if ItemType=Table1 and ItemCondition=Chair1 then i have to give a hard coded value 'Proceed'( this hard coded value i will map to target side of datamapper).
<Root>
<SubRoot>
<ItemType>Table1</ItemType>
<ItemCondition>Chair1</ItemCondition>
<ItemValue>
.......
</ItemValue>
</SubRoot>
<SubRoot>
<ItemType>Table2</ItemType>
<ItemCondition>chair2</ItemCondition>
<ItemValue>
.......
</ItemValue>
</SubRoot>
....Will have multiple subroot
</Root>
I have tried to define rules as below, but it is throwing error
Type: String
Context:/Root
Xpath: substring("Proceed", 1 div boolean(/SubRoot[ItemType="Table1" and ItemCondition="Chair1"]))
But it is throwing error like
net.sf.saxon.trans.XPathException: Arithmetic operator is not defined for arguments of types (xs:integer, xs:boolean)
Is there any other shortcut way to perform this.Could you please help me, i have given lot more effort. Not able to resolve it. Thanks in advance.
I am not sure where you are applying this but the XPath expression you are looking for is:
fn:contains(/Root/SubRoot[2]/ItemCondition, "chair") and fn:contains(/Root/SubRoot[2]/ItemType, "Table")
So here is an example returning "Proceed" or "Stop" as appropriate:
if (fn:contains(/Root/SubRoot[1]/ItemCondition, "Chair") and fn:contains(/Root/SubRoot[2]/ItemType, "Table")) then 'Proceed' else 'Stop'
To implement the above condition , i was initially tired to do in xpath, gave me lot of error. I have implemented by simple if else condition in script part of data mapper
if ( (input.ItemType == 'Table') and (input.ItemCondition == 'chair')) {
output.Item = 'Proceed'}
else {
output.Item = 'Stop '};
Make sure about your precedence. Example, Here in the xml structure( or converted POJO) ItemType has to be checked first then followed with ItemCondition.
&& not seems to be working for me, change to 'and' operator
If you were first time trying to implement the logic. It may help you.

Mixing 'Like' with comparators in an iif statement?

I'm attempting to use the query builder to formulate a query based on user input on a form, but I'm running into an issue.
I've been using this code to filter and check for null/"ALL" field before which is working fine.
Like IIf([Forms]![TransactionsForm]![ComboActStatus]="ALL","*",
[Forms]![TransactionsForm]![ComboActStatus])
But I run into an issue when I want to do the same thing with fields that signify a range. I attempted this:
IIf([forms]![TransactionsForm]![txtAmountFrom] Is Null Or
[forms]![TransactionsForm]![txtAmountTo] Is Null,
([dbo_customerQuery].[amount]) Like "*",
([dbo_customerQuery].[amount])>=[forms]! [TransactionsForm]![txtAmountFrom] And
([dbo_customerQuery].[amount])<=[Forms]![TransactionsForm]![txtAmountTo])
But it's causing my entire query to fail. How can I do this similar thing? Use "Like *" in the null case (return everything), but use comparators rather than "like" statements in the second case?
Unless I'm missing something LIKE "*" will return true for all values, so this should work:
IIf([forms]![TransactionsForm]![txtAmountFrom] Is Null Or
[forms]![TransactionsForm]![txtAmountTo] Is Null,
true,
([dbo_customerQuery].[amount])>=[forms]! [TransactionsForm]![txtAmountFrom] And
[dbo_customerQuery].[amount])<=[Forms]![TransactionsForm]![txtAmountTo])
)
The code that finally worked for me, and didn't have Access split it into separate lines was:
>=IIf([forms]![TransactionsForm]![txtAmountFrom] Is Null,0,[forms]![TransactionsForm]!
[txtAmountFrom]) And <=IIf([forms]![TransactionsForm]![txtAmountTo] Is Null,9999999999,
[forms]![TransactionsForm]![txtAmountTo])

Rails order active record results based on one column and another if null

So I have an active record query that returns some records, lets say it looks like this.
jobs = Job.where(:user_id => current_user.id)
As you would expect this returns the current_user's jobs. Assume that the job has two dates, deadline_date and due_date. If I want to order on deadline_date I can do something like..
jobs.order("deadline_date asc")
That works as expected, now image I have something in the job model like this.
class Job < ActiveRecord::Base
def deadline_date
self.read_attribute(:deadline_date) || self.due_date
end
end
So the job will display its deadline_date if it is not nil else it will fallback to use the due_date. So to sort this I have done the following...
jobs.sort_by{|job| job.deadline_date}
jobs.sort_by{|job| job.deadline_date}.reverse
This solves my problem but I wondered it there were better alternatives, is it possible to achieve this using SQL? Also this produces some repeated code in that I have a sort_order variable in my controllers that I can pass directly like this...
jobs.order(sort_order)
Now it looks more like this...
if params[:sort] == "deadline_date"
if params[:order] == "asc"
jobs.sort_by{|job| job.deadline_date}
else
jobs.sort_by{|job| job.deadline_date}.reverse
end
else
jobs.order(sort_order)
end
Note: This is a arbitrary example in reality it is a bit messy but you get the idea. So I'm looking for an SQL alternative or a suggestion on how it could be improved. Cheers
If I understand you correctly, you should be able to do this using the COALESCE SQL function:
jobs.order(Arel.sql("COALESCE(deadline_date, due_date)"))
That's pretty much the same as deadline_date || due_date in Ruby.
I believe it to be a standard SQL thing, so it should work for most SQL dialects.

Subsonic dynamic query expression

I am having a few issues with trying to live in a subsonic world and being a subsonic girl when it comes to subsonic expressions....
after reading Subsonic Query (ConditionA OR ConditionB) AND ConditionC it would appear i am not the only one with this sort of issue but hopefully someone (the almighty rob??) can answer this.
i am attempting to create an expression in my query based on a looping condition. what i want to achieve (in pseudo code) is something like this:
objQuery.andexpressionstart();
foreach (condition in conditions){
if (condition){
objQuery.and(conditionColumn).isequalto(X);
}
}
objQuery.expressionstop();
my main issue is that each condition that is inside the expression is a different column - otherwise i could just use .In() . i also have extra search criteria (read a fair bit) outside so it can't be outside an expression.
i REALLY don't want to leave the warm coseyness of the strongly-typed-subsonic womb however i think in this instance i might have too... if i DO have to is there a way to add to a subsonic query with a hand typed condition so i don't have to change all the other code in the query (alot of business logic living in subsonic land right now)
As always, thanks for any help
cheers
I haven't the time to test this right now, but I think if you do something like the following should work:
bool isFirstCondition = true;
foreach (condition in conditions){
if (condition)
{
if(isFirstCondition)
{
objQuery.AndExpression(conditionColumn).isequalto(X);
isFirstCondition = false;
}
else
{
objQuery.and(conditionColumn).isequalto(X);
}
}
}
Make sure all your other conditions have been added prior to the loop.