Go Back   CORTEX Forums > Local Happenings > CORTEX Blogs > Random Procrastination
Register Blogs FAQ Members List Calendar Search Today's Posts Mark Forums Read

SSAS: T-SQL Equivalent for a Many-to-Many relationship

This is a discussion on SSAS: T-SQL Equivalent for a Many-to-Many relationship within the Random Procrastination forums, part of the CORTEX Blogs category; This question came a while ago now in this SSAS forum thread: What is wrong in my query and I thought it was something that may interest other people. Basically ...


Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 23rd June 2009, 08:30 PM   #1
Senior Member
 
Join Date: Jun 2009
Posts: 62
Darren Gosbell is on a distinguished road
Thumbs up SSAS: T-SQL Equivalent for a Many-to-Many relationship

This question came a while ago now in this SSAS forum thread: What is wrong in my query and I thought it was something that may interest other people.

Basically it boiled down to trying to find a T-SQL equivalent to the following MDX which is querying a dimension with a many-to-many relationship to the measure.

So given the following simple MDX query, what would be the equivalent in SQL?

*

select measures.[Internet Sales Amount] on 0 , [Sales Reason].[Sales Reasons].[Reason Type].Members on 1FROM [Adventure Works]*

Well, what I came up with was the following where I ended up effectively joining to the fact table twice. I don't know about you, but I'd rather write the MDX version any day. :)

*

SELECT m2m.SalesReasonReasonType ,Sum(f.SalesAmount) FROM FactInternetSales fINNER JOIN ( SELECT DISTINCT salesOrderNumber, SalesOrderLineNumber, D.SalesReasonReasonType FROM [dbo].[DimSalesReason] AS dim INNER Join dbo.FactInternetSalesReason isr ON dim.SalesReasonKey = isr.SalesReasonKey ) m2m on f.SalesOrderNumber = m2m.SalesOrderNumber And f.SalesOrderLineNumber = m2m.SalesOrderLineNumber GROUP BY m2m.SalesReasonReasonType*

Technorati Tags: Analysis Services, MDX, Many to Many, SQL





More...
Darren Gosbell is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiTweet this Post!
Reply With Quote
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
SSAS: Executing Arbitrary SQL queries Darren Gosbell Random Procrastination 0 23rd June 2009 08:30 PM
SSAS: Powershell to replace a group member in a role Darren Gosbell Random Procrastination 0 23rd June 2009 08:30 PM


All times are GMT +11. The time now is 02:44 AM.

© The Business Intelligence Group

Search Engine Optimization by vBSEO