Search code examples
sqlssassql-likedmv

SSAS DMV's NOT LIKE Condition


I have the query that runs OK on SSAS.

SELECT  DIMENSION_NAME
FROM  $SYSTEM.MDSCHEMA_DIMENSIONS
WHERE LEFT(CUBE_NAME,1) = '$'
AND [DIMENSION_UNIQUE_NAME] <> '[Metrics]'
AND [DIMENSION_UNIQUE_NAME] <> '[Measures]'
ORDER BY DIMENSION_NAME

How should I specify NOT LIKE condition to get all Dimension Names that do not start with "Fact"? In T-SQL it is written such as

AND [DIMENSION_UNIQUE_NAME] NOT LIKE 'Fact%'

but how to write it in MDX?


Edit based on comments:

How to write the query so I can filter out elements starting with "Fact" in the name?

The following query returns an error:

SELECT  DIMENSION_NAME ,*
FROM  $SYSTEM.MDSCHEMA_DIMENSIONS
WHERE LEFT(CUBE_NAME,1) = '$'
AND [DIMENSION_UNIQUE_NAME] <> '[Metrics]'
AND [DIMENSION_UNIQUE_NAME] <> '[Measures]'
AND [DIMENSION_UNIQUE_NAME] NOT LIKE 'Fact%'
ORDER BY DIMENSION_NAME

-

Executing the query ...
Query (6, 29) The syntax for 'NOT' is incorrect.
Execution complete

Solution

  • Replace the second last line with this:

    AND LEFT([DIMENSION_UNIQUE_NAME], 4) <> 'Fact'
    

    Hope you are running the statement in a new DMX query window on SSMS