# Database Discussions > MDX and Analysis Services >  Converting from MDX to  SQL

## hmai

Hi all
May I know how the below query can be converted to SQL query?? I am not able to understand how this can be written in SQL....

WITH MEMBER Measures.x AS [Date].[Calendar].[Calendar Quarter].Ordinal
SELECT Measures.x on 0
FROM [Adventure Works]


It would be great help if anybody come up with the answer :Smilie:

----------


## rmiao

How convert to t-sql? Can't query cube with t-sql.

----------


## hmai

I have corresponding DW(based on which cube is created) in the server. I have column mappings as well. I am not able to understand what is the logic are they trying to put in the below query. I have a calculated measure for which the formula is like this 
CASE WHEN [_Date Count] IS NULL THEN NULL
WHEN   [Date].[Days Calendar].CurrentMember.Level.Ordinal = 0
                  AND [Date].[Days Fiscal].CurrentMember.Level.Ordinal = 0
                  AND [Date].[Long Days Fiscal].CurrentMember.Level.Ordinal = 0
                  AND [Date].[Long Weeks Fiscal].CurrentMember.Level.Ordinal = 0
                  AND [Date].[Months Calendar].CurrentMember.Level.Ordinal = 0
                  AND [Date].[Weeks Fiscal].CurrentMember.Level.Ordinal = 0
                  THEN
                  (
                       [Measures].[ResellerSales]
                      ,[Date].[Days Calendar].[Calendar Year].&[CY2014].LastSibling

                  )
               ELSE
                  ( 
                       [Measures].[InternetSales]
                      ,[Date].[Days Calendar].[Calendar Year].&[CY2014].LastSibling
                  )
            END
         )

----------


## rmiao

Take look at 'Using GROUP BY with ROLLUP, CUBE, and GROUPING SETS' in books online.

----------

