2016-04-01 7 views
1

要するに、私はnow()と比較する必要がある日付型のプロパティを持っていますが、この比較が機能する2つの異なる環境(言語設定)があります。MDX言語に依存しない日付比較

私は次のコードを持っている:

with 
    member [Measures].[Opening] as 
     CDate([Store].[Store].Properties('Opening')) // works with the english date 

    member [Measures].[Opening] as // works with the german date 
     DateSerial(
      Right([Store].[Store].Properties('Opening'),4), 
      Mid([Store].[Store].Properties('Opening'),4,2), 
      Left([Store].[Store].Properties('Opening'),2) 
     ) 

    member [Measures].[IsOpen] as 
     CASE 
      WHEN [Measures].[Opening] < NOW() 
       THEN 1 
       ELSE 0 
     END 

[Store].[Store].Properties('Opening')は日付です。

しかし、実行する必要のある言語設定が異なる2つのサーバーがあります。 1つ戻る02.10.2009と[Opening]の他の10/2/2009。

両方の環境で動作するソリューションを見つける必要があります。 (ただし、言語設定を変更することはできません)

FORMAT_STRINGまたはLANGUAGEで書式を設定しようとしましたが、これまでのところ成功しませんでした。

+0

私のスニペットが役に立ちましたか? – whytheq

+0

第3の助けがありました。 –

答えて

1

一つの可能​​性のあるアイデアはこれです: - :

VBA!cdate(
    format(
     VBA!cdate([Store].[Store].Properties('Opening')), 
     "dd MMMM yyyy" 
    ) 
) 

倉庫の多くは、その日付のキーとして整数を使用しますが、建設のこの種を使用することができますよう、サーバの日付フォーマットはやや無関係のだろう

MEMBER [Measures].[Date as int] as 
     [Date].[Date].CURRENTMEMBER.Properties('Key0', Typed) 
MEMBER [Measures].[Date Year] as 
     Fix([Measures].[Date as int]/10000) 
MEMBER [Measures].[Date Month] as 
     Fix(([Measures].[Date as int] - [Measures].[Date Year] * 10000)/100) 
MEMBER [Measures].[Date Day] as 
     [Measures].[Date as int] - [Measures].[Date Year] * 10000 - [Measures].[Date Month] * 100 

MEMBER [Measures].[DateValue_attempt1] as 
     // convert it to Date data type and use a format string on that: 
     DateSerial([Measures].[Date Year], [Measures].[Date Month], [Measures].[Date Day]), 
     format_string = 'dd.MM.yyyy' 
MEMBER [Measures].[DateValue_attempt2] as 
     //if above fails maybe just convert it to string & do further conversion in client 
     [Measures].[Date Day] + "." + 
      [Measures].[Date Month] + "." + 
      [Measures].[Date Year] 

しかし、あなたのための回避策のビットは3番目の文字が何であるかを検出し、IIFまたはCASEを使用することがあります

WITH 
    MEMBER [Measures].[Opening] AS 
     IIF(
      Mid([Store].[Store].Properties('Opening'),3,1) = '.' 
     ,DateSerial(
      Right([Store].[Store].Properties('Opening'),4), 
      Mid([Store].[Store].Properties('Opening'),4,2), 
      Left([Store].[Store].Properties('Opening'),2) 
     ) 
     ,CDate([Store].[Store].Properties('Opening')) 
     )