Search code examples
ssasmdxbusiness-intelligence

MDX Query STRTOSET CONSTRAINED flag


I'm not familiar with the MDX language and I got a problem with a Dataset (DataBatchProcessData), this is the MDX query :

SELECT 
  NON EMPTY 
    {
      [Measures].[Germ1 Delta Temp In Out Inf]
     ,[Measures].[Germ2 Delta Temp In Out Sup]
     ,[Measures].[Germ2 Delta Temp In Out Inf]
     ,[Measures].[Germ1 Delta Temp In Out Sup]
     ,[Measures].[Germ Nb Sprays]
    } ON COLUMNS
 ,NON EMPTY 
    {
        [65 Batch Process Data].[Batch Number].[Batch Number].ALLMEMBERS*
        [01 Plants].[Plant Name].[Plant Name].ALLMEMBERS*
        [04 Production Units].[Production Unit].[Production Unit].ALLMEMBERS*
        [65 Batch Process Data].[Steeping Start Date].[Steeping Start Date].ALLMEMBERS
    }
  DIMENSION PROPERTIES 
    MEMBER_CAPTION
   ,MEMBER_UNIQUE_NAME
   ON ROWS
FROM 
(
  SELECT 
    StrToSet
    ("{[65 Batch Process Data].[Batch Number].&[1320165073],[65 Batch Process Data].[Batch Number].&[1320165074],[65 Batch Process Data].[Batch Number].&[1320165075]}"
     ,CONSTRAINED
    ) ON COLUMNS
  FROM 
  (
    SELECT 
      StrToSet
      ("[04 Production Unit].[Production Unit].&[1]"
       ,CONSTRAINED
      ) ON COLUMNS
    FROM 
    (
      SELECT 
        StrToSet
        ("[01 Plants].[Plant Name].&[Rostock]"
         ,CONSTRAINED
        ) ON COLUMNS
      FROM [Supervision]
    )
  )
)
CELL PROPERTIES 
  VALUE
 ,BACK_COLOR
 ,FORE_COLOR
 ,FORMATTED_VALUE
 ,FORMAT_STRING
 ,FONT_NAME
 ,FONT_SIZE
 ,FONT_FLAGS;

This MDX Query was autogenerated by SSRS, but is not working, I got this error when running my report:

Query (8, 9) The restrictions imposed by the CONSTRAINED flag in the STRTOSET function were violated.

I got another DataSet (DataGermination) that is quite similar to this Dataset, and it take the same parameters (not in the same dimension tho) :

SELECT 
  NON EMPTY 
    {
      [Measures].[Air Temperature Out - Fact Germination Continue]
    } ON COLUMNS
 ,NON EMPTY 
    {
        [81 Germination Continue].[Batch Number].[Batch Number].ALLMEMBERS*
        [80 Germination General].[Plant Name].[Plant Name].ALLMEMBERS*
        [80 Germination General].[Production Unit].[Production Unit].ALLMEMBERS*
        [81 Germination Continue].[Characteristic Date].[Characteristic Date].ALLMEMBERS*
        [80 Germination General].[Start Date  Unloading].[Start Date  Unloading].ALLMEMBERS*
        [80 Germination General].[Start Date].[Start Date].ALLMEMBERS*
        [80 Germination General].[End Date].[End Date].ALLMEMBERS
    }
  DIMENSION PROPERTIES 
    MEMBER_CAPTION
   ,MEMBER_UNIQUE_NAME
   ON ROWS
FROM 
(
  SELECT 
    StrToSet
    ("[80 Germination General].[Production Unit].&[1]"
     ,CONSTRAINED
    ) ON COLUMNS
  FROM 
  (
    SELECT 
      StrToSet
      ("[80 Germination General].[Plant Name].&[Rostock]"
       ,CONSTRAINED
      ) ON COLUMNS
    FROM 
    (
      SELECT 
        StrToSet
        ("{[81 Germination Continue].[Batch Number].&[1320165073],[81 Germination Continue].[Batch Number].&[1320165074],[81 Germination Continue].[Batch Number].&[1320165075]}"
         ,CONSTRAINED
        ) ON COLUMNS
      FROM [Supervision]
    )
  )
)
CELL PROPERTIES 
  VALUE
 ,BACK_COLOR
 ,FORE_COLOR
 ,FORMATTED_VALUE
 ,FORMAT_STRING
 ,FONT_NAME
 ,FONT_SIZE
 ,FONT_FLAGS;

When I run these query in SSMS, the 2nd one is working (DataGermination), but I don't know why, the dataset DataBatchProcessData is not.


Solution

  • From BOL:

    When the CONSTRAINED flag is used, the set specification must contain qualified or unqualified member names or a set of tuples containing qualified or unqualified member names enclosed by braces {}. This flag is used to reduce the risk of injection attacks via the specified string. If a string is provided that is not directly resolvable to qualified or unqualified member names, the following error appears: "The restrictions imposed by the CONSTRAINED flag in the STRTOSET function were violated.

    Looks like you are not using the fully qualified member name for the attributes.

    It needs to be

    Dimension Name.Hierarchy Name.Level Name.Member Name
    

    or

    Dimension Name.Hierarchy Name.Level Name.&[Member Value]