Showing posts with label thisselect. Show all posts
Showing posts with label thisselect. Show all posts

Thursday, February 16, 2012

About Members and Ordinal function

When I use MDX sample application,
I write a code like this:

SELECT

{[Time].[All Time].[2005]} ON COLUMNS,

{Filter([Equipment].Members, (InStr(1, [Equipment].CurrentMember.Name, "xxxx") =1))} ON ROWS

FROM francis.

Here Equipment is a huge dimension table,actually I want to do it like

Filter([Equipment].[All types].[mechanism].Members to narrow the range as prevent duplicate.
But it failed.

One more is I can't use ordinal function in it too, but I can do it in AS and test in pivottables.

Can someone tell me the reasons?
This is probably the same issue as I mentioned on the other thread - you probably need to use the .Children function instead of the .Members function. The .Children function returns all the members 'underneath' a member in a hierarchy, the .Members function returns all the members on a dimension or level. So:
[Equipment].[All types].[mechanism].Children
should work for you.

I'm not sure what you mean about your problem with the Ordinal function - can you provide more details?

Chris|||Hi, Chris, give you more details as example. I assume[Equipment].[All types].[mechanism].[machine001] have [abc],[bcd],[efg],[hij] these children like [Equipment].[All types].[mechanism].[machine001].[abc], and in them they all have a children call [ABSmain_xxxx] like [Equipment].[All types].[mechanism].[machine001].[abc].ABSmain_abc.
Now I want to average all the ABSmain_xxx value, so I will do a filter to the set I reach now.
If I use [Equipment].[All types].[mechanism].[machine001].Children, it will only filter the [abc],[bcd]...etc, it won't go deep to their children.
I suppose to do it like [Equipment].[All types].[mechanism].[machine001].[abc].level.members,I think it will work.

|||No, your last example won't do what you want, I think - it will return all the members on the same level as[Equipment].[All types].[mechanism].[machine001].[abc]. Does[Equipment].[All types].[mechanism].[machine001].[abc].CHILDREN do what you want? Otherwise, you might want to check out the DESCENDANTS function.

You might want to read some of the articles in the 'MDX Essentials' series here:
http://www.databasejournal.com/article.php/1459531/
Especially the ones on 'family' functions such as this one:
http://www.databasejournal.com/features/mssql/article.php/2168911

HTH,

Chris|||Hi, Chris, I have checked the descendants function and it is the one I want, it works fine expect for a little longer query time than I thought.

About Members and Ordinal function

When I use MDX sample application,
I write a code like this:

SELECT

{[Time].[All Time].[2005]} ON COLUMNS,

{Filter([Equipment].Members, (InStr(1, [Equipment].CurrentMember.Name, "xxxx") =1))} ON ROWS

FROM francis.

Here Equipment is a huge dimension table,actually I want to do it like

Filter([Equipment].[All types].[mechanism].Members to narrow the range as prevent duplicate.
But it failed.

One more is I can't use ordinal function in it too, but I can do it in AS and test in pivottables.

Can someone tell me the reasons?
This is probably the same issue as I mentioned on the other thread - you probably need to use the .Children function instead of the .Members function. The .Children function returns all the members 'underneath' a member in a hierarchy, the .Members function returns all the members on a dimension or level. So:
[Equipment].[All types].[mechanism].Children
should work for you.

I'm not sure what you mean about your problem with the Ordinal function - can you provide more details?

Chris|||Hi, Chris, give you more details as example. I assume [Equipment].[All types].[mechanism].[machine001] have [abc],[bcd],[efg],[hij] these children like [Equipment].[All types].[mechanism].[machine001].[abc], and in them they all have a children call [ABSmain_xxxx] like [Equipment].[All types].[mechanism].[machine001].[abc].ABSmain_abc.
Now I want to average all the ABSmain_xxx value, so I will do a filter to the set I reach now.
If I use [Equipment].[All types].[mechanism].[machine001].Children, it will only filter the [abc],[bcd]...etc, it won't go deep to their children.
I suppose to do it like [Equipment].[All types].[mechanism].[machine001].[abc].level.members,I think it will work.

|||No, your last example won't do what you want, I think - it will return all the members on the same level as [Equipment].[All types].[mechanism].[machine001].[abc]. Does [Equipment].[All types].[mechanism].[machine001].[abc].CHILDREN do what you want? Otherwise, you might want to check out the DESCENDANTS function.

You might want to read some of the articles in the 'MDX Essentials' series here:
http://www.databasejournal.com/article.php/1459531/
Especially the ones on 'family' functions such as this one:
http://www.databasejournal.com/features/mssql/article.php/2168911

HTH,

Chris|||Hi, Chris, I have checked the descendants function and it is the one I want, it works fine expect for a little longer query time than I thought.

Thursday, February 9, 2012

About CASE and WHERE

*I have a Query like this:
SELECT CARTERA_PROV.cCAJA,
CAJA.sCAJA,
CARTERA_PROV.fEMISION,
CARTERA_PROV.fVENCIMIENTO
FROM
CARTERA_PROV,
ANEXO,
TIPO_DOCUMENTO,
CAJA,
CONCEPTO_GASTO,
MOVIMIENTO_CAJA
WHERE
case CARTERA_PROV.cCONCEPTO_CARTERA
when '38' then CARTERA_PROV.gTIPO_PRESTAMO
else MOVIMIENTO_CAJA.gTIPO_PRESTAMO
end = #ANY VALUE#
AND
(...)
*Whatever the value I put instead of #ANY VALUE#, the query ALWAYS analyze
TRUE all this sentence:
case CARTERA_PROV.cCONCEPTO_CARTERA
when '38' then CARTERA_PROV.gTIPO_PRESTAMO
else MOVIMIENTO_CAJA.gTIPO_PRESTAMO
end = #ANY VALUE#
*Can someone explain me that please? I don't think is a bug.
Regards,
Ral La TorreHmm. It seems that what you have should work fine.
Here is an example that shows the results. The query correctly returns the
1st and 4th rows but does not return the 2nd and 3rd rows.
CREATE TABLE TestTable(column1 int, column2 int, column3 int)
GO
INSERT INTO TestTable VALUES(1,2,5)
INSERT INTO TestTable VALUES(2,2,5)
INSERT INTO TestTable VALUES(3,5,5)
INSERT INTO TestTable VALUES(4,2,2)
GO
select *
from TestTable
WHERE CASE column1
WHEN 1 THEN column2
ELSE column3
END = 2
HTH
--
Ryan Powers
Clarity Consulting
http://www.claritycon.com
"Raul La Torre" wrote:

> *I have a Query like this:
> SELECT CARTERA_PROV.cCAJA,
> CAJA.sCAJA,
> CARTERA_PROV.fEMISION,
> CARTERA_PROV.fVENCIMIENTO
> FROM
> CARTERA_PROV,
> ANEXO,
> TIPO_DOCUMENTO,
> CAJA,
> CONCEPTO_GASTO,
> MOVIMIENTO_CAJA
> WHERE
> case CARTERA_PROV.cCONCEPTO_CARTERA
> when '38' then CARTERA_PROV.gTIPO_PRESTAMO
> else MOVIMIENTO_CAJA.gTIPO_PRESTAMO
> end = #ANY VALUE#
> AND
> (...)
>
> *Whatever the value I put instead of #ANY VALUE#, the query ALWAYS analyze
> TRUE all this sentence:
> case CARTERA_PROV.cCONCEPTO_CARTERA
> when '38' then CARTERA_PROV.gTIPO_PRESTAMO
> else MOVIMIENTO_CAJA.gTIPO_PRESTAMO
> end = #ANY VALUE#
>
> *Can someone explain me that please? I don't think is a bug.
> Regards,
> Raúl La Torre
>
>|||Just guessing, but try putting your case statement inside parenthesis.
Maybe the entire statement is not parsing as a whole and this will force it
to be handled as you desire. Adding in parentheses and some indentation can
make the code more readable anyway.
However,
I don't see why case is needed, or even useful here. I think an OR will be
easier to follow, more standard (i.e. not proprietary), portable, and more
efficient (I may be wrong here, still learning my way around the SQL tuning
process).
(
(CARTERA_PROV.gTIPO_PRESTAMO = #ANY VALUE# and
CARTERA_PROV.cCONCEPTO_CARTERA = 38)
or
(MOVIMIENTO_CAJA.gTIPO_PRESTAMO = #ANY VALUE# and
CARTERA_PROV.cCONCEPTO_CARTERA <> 38)
)
"Raul La Torre" <raul_la_torre@.hotmail.com> wrote in message
news:usHr%23l8GGHA.3896@.TK2MSFTNGP15.phx.gbl...
> *I have a Query like this:
> SELECT CARTERA_PROV.cCAJA,
> CAJA.sCAJA,
> CARTERA_PROV.fEMISION,
> CARTERA_PROV.fVENCIMIENTO
> FROM
> CARTERA_PROV,
> ANEXO,
> TIPO_DOCUMENTO,
> CAJA,
> CONCEPTO_GASTO,
> MOVIMIENTO_CAJA
> WHERE
> case CARTERA_PROV.cCONCEPTO_CARTERA
> when '38' then CARTERA_PROV.gTIPO_PRESTAMO
> else MOVIMIENTO_CAJA.gTIPO_PRESTAMO
> end = #ANY VALUE#
> AND
> (...)
>
> *Whatever the value I put instead of #ANY VALUE#, the query ALWAYS analyze
> TRUE all this sentence:
> case CARTERA_PROV.cCONCEPTO_CARTERA
> when '38' then CARTERA_PROV.gTIPO_PRESTAMO
> else MOVIMIENTO_CAJA.gTIPO_PRESTAMO
> end = #ANY VALUE#
>
> *Can someone explain me that please? I don't think is a bug.
> Regards,
> Ral La Torre
>