Showing posts with label differs. Show all posts
Showing posts with label differs. Show all posts

Sunday, March 25, 2012

Difference Between Comma Operator and Crossjoin?

I have two queries that appear to return the same result. Can someone explain how combining two dimensions with the comma operator differs from combining the same two dimensions using the crossjoin operator?

For example, two dimensions, account and sales. When I run this query with the cross join operator

select { [Measures].[Sales Count] } on columns,

{ ([Account].[Name].Allmembers *

[Date].[Month Val].[5] : [Date].[Month Val].Devil

) } on rows

from warehouse

it returns the same results as this query when using the comma operator to create the set:

select { [Measures].[Sales Count] } on columns,

{ ([Account].[Name].Allmembers ,

[Date].[Month Val].[5] : [Date].[Month Val].Devil

) } on rows

As crossjoin states, in example 1 above, every account is combined with every month value. When using the comma operator, I see the exact same results. Are these functionally equivalent? Any reason to use one method over the other?

Thanks....

AS2005 can be very forgiving - perhaps too forgiving - with MDX syntax...

First of all, despite appearances, there is no comma operator: the comma is used as a delimiter within a set and a tuple definition. Crossjoin you're ok with. What you're doing in your queries is producing a set of tuples containing every month crossjoined with every account and for the sake of clarity this is best written as an explicit crossjoin, either using the asterisk operator or the crossjoin function, something like this:

select { [Measures].[Sales Count] } on columns,
[Account].[Name].Allmembers * {[Date].[Month Val].[5] : [Date].[Month Val].Devil}
on rows
from warehouse

In your first query you're putting the above crossjoin operation inside a set of parentheses (), which denote a tuple - and which AS is ignoring because you're producing a set of tuples anyway. In the second query because you've put a set definition rather than a member as the second item in your tuple definition AS must be assuming that you want to do a crossjoin and is again returning the set of tuples you're after, but this behaviour is new to me and from a maintenance point of view should probably be avoided.

Chris

|||

Hi Chris,

I'm wondering whether the comma syntax in the 2nd example (which I also recall being mentioned in Teo Lachev's As 2005 book) is technically a subcube expression, as defined for the SCOPE script statement or a Cell Calculation:

http://msdn2.microsoft.com/en-us/library/ms145989.aspx

>>

Subcube_Expression ::= (Auxiliary_Subcube [, Auxiliary_Subcube,...n])

Auxiliary_Subcube ::=
Limited_Set
| Root([dimension_name])
| Leaves([dimension_name])

>>

Mosha had mentioned in his blog that a subcube could get converted to a set, under certain circumstances (though unsupported):

http://sqljunkies.com/WebLog/mosha/archive/2006/04/29/leaves.aspx

>>

How to work with Dimension Leaves

While Analysis Services may convert subcube returned by Leaves function to set (by choosing attribute hierarchies corresponding to the attributes), it is not supported usage.

>>

|||

Hmmm, possibly... In which case, if Mosha says it's unsupported, it's definitely to be avoided.

Chris

|||Agreed...crossjoin works fine. Thanks for the feedback.

Thursday, March 22, 2012

difference

hello!
sorry, i don´t speak english.
hello again!
It what differs it is between these two sentence?
- exec (' exec sp_MShelpindexPru cliente,'+''+@.indexid+''+'output')
-exec sp_MShelpindexPru cliente,@.indexid output
Supposedly, they are equal , no?
None gives me mistake, but The first one does not give me a result And
the second one gives me the correct result. Which is the difference
between both?
I need to do it of the second form, because I need to insert one it
use @.dbname initially.
Thank you very much, and excuses me for my English. :-(Look into using sp_execute_sql instead. See if this helps:
http://support.microsoft.com/default.aspx?scid=kb;en-us;262499
--
HTH,
Vyas, MVP (SQL Server)
http://vyaskn.tripod.com/
What hardware is your SQL Server running on?
http://vyaskn.tripod.com/poll.htm
<mani14@.begira.com> wrote in message
news:ca48b635.0308190221.9b9a596@.posting.google.com...
hello!
sorry, i don´t speak english.
hello again!
It what differs it is between these two sentence?
- exec (' exec sp_MShelpindexPru cliente,'+''+@.indexid+''+'output')
-exec sp_MShelpindexPru cliente,@.indexid output
Supposedly, they are equal , no?
None gives me mistake, but The first one does not give me a result And
the second one gives me the correct result. Which is the difference
between both?
I need to do it of the second form, because I need to insert one it
use @.dbname initially.
Thank you very much, and excuses me for my English. :-(|||Hello Mani !
But remeber that for SP_executesql the @.string followed to be executed must
be NVARCHAR !
Jens Süßmeyer.