MDX Help and tutorial - mdx

Hello guys again here with my MDX headaches (why does my boss think programmer = solve anything computer related).
The measure of the Filter
Productos is compose this way [Casa].[Linea].[Producto] and I am trying to filter by Linea 72 and 74, outside this anyone know a good tutorial online or book for MDX?
Anyways here my MDX so far
SELECT 'Dic 1 2010' AS Fecha, A.*
from (SELECT
"[Measures].[Piezas Dia]",
"[Measures].[P Redondeadas]"
FROM openrowset('MSOLAP'
,'DATASOURCE=XXX
;Initial Catalog=XXX
; User Id=XXX;Password=XXX;',
'WITH SET [Lineas] AS ''
FILTER(DESCENDANTS([PRODUCTOS],[LINEA],SELF),
ANCESTOR([PRODUCTOS].CURRENTMEMBER,SELF) <> [74 VARIOS] AND
ANCESTOR([PRODUCTOS].CURRENTMEMBER,SELF) <> [72 VARIOS] )''
Member [Measures].[Piezas Dia] AS ''sum([Lineas],[Measures].[|P| Venta Dia Año Actual])''
Member [Measures].[P Redondeadas] AS ''sum([Lineas],[Measures].[Venta Piezas Redondeadas])''
SELECT {[Measures].[Piezas Dia], [Measures].[P Redondeadas]} on columns
FROM [Venta Gerencial]
WHERE ([Fecha Diario].[Fecha].&[2010].&[12].&[1])')) as A
Thanks for all help provided.

You can find an 'gentle' introduction to MDX here

You asked for a book referral. My boss just purchased SQL Server 2008 MDX Step by Step for me. I'm beginning to go through it and I like the way it is laid out. I've been programming in T-SQL for over ten years and MDX is just close enough to confuse me. This book is helping me think different about my code and coding practices. I haven't finished it, but I do think that it might be a good one for you to start with, as you can jump in anywhere in the book to learn what you need to know.

Should it really be a , instead of a ; here:
FROM openrowset('MSOLAP' ***,*** 'DATASOURCE=HDZNT10

Related

SPARQL PROTEGE: Filtering by a string name

so here is the problem. I need to show the member of a university who are interested in Semantic web. I tried everything but I think there is something I don't really see maybe someone can help me.
SELECT ?interest ?membre
{ ?UER_ST foaf:member ?membre.
?membre foaf:interest ?interest
}

Case Statement Assistance

I have a case statement currently built but need to add an extra layer and I'm not sure of the most efficient and accurate way of doing it. I have these drug codes that are for SYRINGE usage, and another set of codes for PEN usage. I have those layers built in, easy enough. I am trying to add a third layer to determine if the member used both a pen and a syringe, so the member would have a code from both categories during my specified time period. Any ideas? Thanks in advance for the help!
, CASE WHEN NDC.GPI IN (
'2710400300D220',
'2710400300D233',
'2710400300D236',
'2710400400D220',
'2799100225D220',
'2799100235D220') THEN 'PEN'
WHEN NDC.GPI IN (
'27104004002022',
'27104010002005',
'27104020001805',
'27104070001820',
'2730001000E530') THEN 'SYRINGE'
ELSE 'OTHER' END AS DOSAGE_FORM

Regex in redshift

I have a problem.. I need to extract from this field:
exchange<=><br>type<=>full<br>cont<=>part<br>req<=>no<br>money<=>money<br>money<=>3100,4000,0,month<br>boss<=>0
five informations:
full
part
3100
4.4000
5.month
I have tried to use regexp_substr():
regexp_substr(column,'type<=>[^<br>]*') but I dont have any knowledge about regex and I cant do it in a properly way.. can you help me with that?
I never worked with redshift but with regex I can help you:
"(type|cont|money)<=>([^<,]+)(,([^<,]+),[^<,]+,([^<,]+))?"
The capture number 4 in the string you put as an example it will capture all you need, it even exclude the 0 :
Group 1: money
Group 2: 3100
Group 3: ,4000,0,month
Group 4: 4000
Group 5: month
In case you have problems, tell me.
If you want to master your regex skills I can teach you, it will be useful.

Product Index Using Django ORM

I have a list of Products with a field called 'Title' and I have been trying to get a list of initial letters with not much luck. The closes I have is the following that dosn't work as 'Distinct' fails to work.
atoz = Product.objects.all().only('title').extra(select={'letter': "UPPER(SUBSTR(title,1,1))"}).distinct('letter')
I must be going wrong somewhere,
I hope someone can help.
You can get it in python after the queryset got in, which is trivial:
products = Project.objects.values_list('title', flat=True).distinct()
atoz = set([i[0] for i in products])
If you are using mysql, I found another answer useful, albeit using sql(django execute sql directly):
SELECT DISTINCT LEFT(title, 1) FROM product;
The best answer I could come up with, which isn't 100% ideal as it requires post processing is this.
atoz = sorted(set(Product.objects.all().extra(select={'letter': "UPPER(SUBSTR(title,1,1))"}).values_list('letter', flat=True)))

Nhibernate - How to debug "Antlr.Runtime.NoViableAltException"?

With many HQL queries, time and time again I am getting this exception:
Antlr.Runtime.NoViableAltException
This is really generic and unhelpful - does anyone know how best to debug this? Obviously it's a problem with my HQL - but without any clue as to what exactly is wrong it's very much a case of trial and error. I'm pulling my hair out every time I see this.
Note, I don't want to post any HQL here, becuase it's something that I am often coming across, not a problem related to one query.
Does anyone know the best way to tackle this? Is there any tool for validating HQL queries?
Have a look at NHibernate Query Analyzer. It is not perfect, but it will be helpful in many situations.
I can't help you directly, here's something I can share.
When dealing with hibernate or nhibernate (NH), I generally debug by enabling logging on the nhibernate's log4net, or/and the logging of queries at the DB side (e.g. mysql).
They can tell me what is the queries being formulated and executed at the DB and what are the exceptions thrown back by the DB.
For instance, if you have the following error:
Exception of type 'Antlr.Runtime.NoViableAltException' was thrown. near line 1, column
745 [select afe.AFEDataId, afe.Name, afe.AdditionalDescription, afe.ProjectType,
afe.BusinessUnit, afe.plantId, afe.fuelTypeId, afe.DisplayStatus, afe.BudgetedAmount,
sum(exp.Amount), afe.CreatedDate from Company.AFE.Model.AFEData as afe inner join
afe.Expenditures as exp inner join exp.ExpenditureType where (afe.Status.StatusId =
:statusId) and (afe.IsRestrictedVisibility = false OR (select count(AFEDataId) from
Company.AFE.Model.Reader as r where r.AFEData.AFEDataId = afe.AFEDataId AND
r.Contact.ContactId = '70bc6350-c466-40d5-a067-9d1f00bed7dc') > 0 OR (select count(AFEDataId)
from Company.AFE.Model.Editor as e where e.AFEData.AFEDataId = afe.AFEDataId AND
e.Contact.ContactId = '70bc6350-c466-40d5-a067-9d1f00bed7dc') > 0 OR 1=1) afe.AFEDataId,
afe.Name, afe.AdditionalDescription, afe.ProjectType, afe.BusinessUnit, afe.plantId,
afe.fuelTypeId, afe.DisplayStatus, afe.BudgetedAmount, afe.CreatedDate order by afe.Name ASC]
Go and look at character 745 from the original query that was provided and check to see if there is a spelling error, as there was in this one that I just looked at.
Which version of NH you used, for the latest version, the query exchange has some updated, such as you can't use "count(1)" in query, must change to count([alias name]), NH will translate to "select class.id from ... "