MDX: multiple KEYx dimension properties behave strangely - mdx

There are some values in a cube having complex key (e.g., [Period].[Fiscal].[FMonth].&[2000]&[7]). Sometimes I need to receive this key.
In other cases (with simple key) I did it like SELECT [dimension].[hierarchy].[level] DIMENSION PROPERTIES KEY0 and everything was fine, but when I tried to execute SELECT [Period].[Fiscal].[FMonth] DIMENSION PROPERTIES KEY0, KEY1 I've got two properties named [KEY0] both valued with key's second part. I still can get either KEY0 or KEY1 separately, but never at once.
What am I doing wrong? OLAP server is MS 2008.

Related

SQL Direct Reference to Data

Is there a way in Microsoft SQL to reference a specific item of data based on table, column and record?
For example, table A (COL1 INT, COL2 INT) has 2 records (1,2) and (3,4). Can I somehow capture value 4 by reference, rather than as "4"?
The purpose is to allow me to create an audit method that can point to specific value in a (table, column, record) without having to duplicate that value in my audit table (which could be large, therefore bloating my database size).
I am thinking ... just like Object_Id identifies a particular SQL object, so would this reference (some kind of GUID, perhaps?) identify a specific piece of data.
Many thanks in advance.
The answer is No. In MS SQL (and, as far as I know in other popular databases) there are no such references to specific values.
Moreover, even table rows in MS SQL do not have embedded unique identifiers, unless you take care to create an IDENTITY column.
You can yourself make the implementation of such references. For example, create a table with columns
data_id,
table_name,
row_id,
column_name
and fill it up every time you need a reference. Then you can refer to piece of data by data_id.
But this is not a good solution.
in most cases, a single entry in this table will consume more space
than the referenced data value itself
to get the values ​​you still have to use dynamic sql
this will only work for tables that have an IDENTITY column and it
has the same name for all tables
and so on

How to browse using Name column in SSAS cube, when Name column is different from Key column

I have a table where a user has multiple contacts. Now, since the contacts can be duplicate, the key column for contacts is changed to unique key in table.
The cube processed successfully. However, when browsed using contacts attribute, it is considering same contact as different ones as the key column is different for both entries.
Any workaround for this?
You can query for the key by using MEMBER_KEY or Key0 per the dimension member properties. For more information, please refer to Intrinsic Member Properties.

Star Schema - Fact table without uniqueness

We have a data warehouse that contains a large fact table with over 100 million rows. I'm trying to create a cube that includes this fact table and need to create a fact dimension based off of this table. The issue that I'm running into is that there is no way to find uniqueness on this table using the fields that would be included in the fact dimension, without using every field in the table.
I created a surrogate key in the dsv using:
Row_Number() OVER (ORDER BY ID, Dt, Num)
I've used this method to create a surrogate key in another dsv and it worked, but I was also able to find uniqueness with the fields in the Order By.
When I browse the cube based on this fact table I get the correct results when using regular dimensions. When I try to use fields from fact dimension I get eroneous results in most cases...some are correct, though very few.
Would this be a case where I should request that a surrogate key get created on the fact table? Is there a better solution that someone could suggest?

Batch insert return identity and object reference/sequence

With SQL Server 2K8 from C# I'm trying to do a batch insert/updates of records to a parent/child tables to optimize.
The inserts/updates will generate a key automatically which I'd like to extract via an OUTPUT, etc. and then reassign back in the domain model. For batch inserts I need to keep track of which newly generated ID belongs to which domain object in the batch list.
This example comes close to what I need, but was wondering if there's a way to not have an extra column added to the table (SequenceNumber) and still achieve the same results: http://illdata.com/blog/2010/01/13/sql-server-batch-inserts-of-parentchild-data-with-ibatis/
ie. could we rely on the order of the inserts generated from the OUTPUT into the temp table, or pass a ref GUID set on the data model and passed temporarily to the SQL just for reference purposes?
In SQL Server 2008 it is possible to use merge and output to get a mapping between the generated key and the key used in the staging table.
Have a look at this question. Using merge..output to get mapping between source.id and target.id
Unless I've misunderstood...
A surrogate key (IDENTITY or NEWID etc) isn't your actual object identifier. It's an implementation detail and has no intrinsic meaning.
You must have another identifier (name, ISBN, serial number, transaction code/date, etc) that is the real (natural) key.
Your OUTPUT clause can return the surrogate key and the natural key. You then use this to map back

Creating an ADO.NET Entity from primary key-less view (or stored procedure)

Using either a view and/or stored procedure, I can return the results of executing an MDX query against SQL Analysis Services (using OPENROWSET against a linked SSAS Server into SQL).
Unfortunately, the resultset doesn't include a PK field...or for that matter, even a column which COULD act as a PK if I were to hack the model.
Can anyone think of a hacktacular trick I can use to:
Add a field to my result which inserts some auto-incrementing value (to act as a PK candidate)
Somehow set this field to be the PK so that I can easily build an entity off of it?
I'm 99% sure the answer is "no". At this point I can already get data back from SSAS by using an SSRS report with OData rendering...but I have to create my types manually when I use play w/ LINQ.
If someone can nail #1 & #2 for me, this may be a potentially better way to access the data since the Modeler would create my types (entities) for me.
Thanks!
I'm not sure I understand why you can't have a column that could act as a primary key. I just ran a similar query against one of my cubes filtered to a list of members and each column name contained the member name. Here is an example:
Submission:
SELECT Measures.members ON ROWS,
Customer.[CustomerIdKeyField].[UniqueCustomerId] ON COLUMNS
FROM [Postage Prints]
Returned:
(colum header) [Measures].[MeasuresLevel].[MEMBER_CAPTION] [Customer].[CustomerIdKeyField].&[UniqueCustomerId]
(row) Measure1 9.6800000000000015
(row) Measure2 22
(row) Measure3 1