简而言之:我有一个日期类型属性,我需要与now()进行比较,但有两种不同的环境(语言设置),这种比较必须有效。
我有以下代码:
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')
是约会。
但是有两台服务器具有不同的语言设置,必须运行。一个返回例如2009年10月2日和[开放]的其他10/2/2009。
我需要找到适用于这两种环境的解决方案。 (但无法更改语言设置)
我尝试使用FORMAT_STRING或LANGUAGE进行格式化,但是没有成功。
答案 0 :(得分: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]
但是,您可能需要检查第三个字符是什么,然后使用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'))
)