2016-04-01 25 views
1

Özetle: now() ile karşılaştırmam gereken, ancak bu karşılaştırmanın çalışması gereken iki farklı ortam (dil ayarı) gereken bir tarih yazım var.MDX dili bağımsız tarih karşılaştırması

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') bir tarihtir:

Ben şu kodu var.

Ancak, farklı dil ayarlarına sahip iki sunucunun çalışması gerekir. Biri, örn. [Açılış] için 02.10.2009 ve diğer 10/2/2009.

Her iki ortam için çalışan bir çözüm bulmam gerekiyor. (Dil ayarlarını değiştiremezsiniz)

Biçimlendirmeyi FORMAT_STRING veya LANGUAGE ile denedim, ancak ne kadar başarı elde etmedim.

+0

Parçacıklardan hangisi yardımcı oldu? – whytheq

+0

üçüncü yardım etti. –

cevap

1

olası bir düşüncenin:

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

onların tarih tuşları olarak sayıları kullanmayı depolarda bir sürü - Eğer inşaat bu tür kullanmaya devam edebileceği için, sonra sunucunun tarih biçimi hafifçe irrelevent olacaktır:

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] 

Ama üçüncü karakter ne algılamak ve daha sonra kullanmak olabilir için geçici bir çözüm biraz IIF veya 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')) 
     ) 
İlgili konular