简体   繁体   English

Windows窗体C#中形成的动态mdx查询中的转义百分比字符(%)

[英]Escape percentage character (%) in a dynamic mdx query formed in windows forms C#

How do i escape "%" character in a dynamic MDX. 如何在动态MDX中转义“%”字符。 I want "%" to be treated as a literal and not a wild card in MDX. 我希望在MDX中将“%”视为文字而不是通配符。 Here is a basic idea of what is happening : I have a windows form (using c#) where user can create a dynamic search expression for MDX query. 这是正在发生的事情的基本思想:我有一个Windows窗体(使用c#),用户可以在其中为MDX查询创建动态搜索表达式。 Eg Currency Contains US 例如,货币包含 美国

where "Currency" is static, condition "Contains" is a dropdown selectable value and then a textbox for "US". 其中“货币”是静态的,条件“包含”是下拉选择值,然后是“美国”的文本框。

So user clicks "Search" and a dynamic MDX is formed with above condition and a cube hit occurs. 因此,用户单击“搜索”,就会在上述条件下形成动态MDX,并且发生多维数据集命中。

Now, i dont get correct result when query is like : 现在,当查询如下时,我没有得到正确的结果:

Calculation Contains 50% 计算包含 50%

Here, % is treated as wild card and anything containing "50" is shown. 此处,%被视为通配符,并且显示任何包含“ 50”的内容。 Please Help. 请帮忙。 I have tried quotes "", square brackets [], back slash \\, double characters %%. 我尝试使用引号“”,方括号[],反斜杠\\,双字符%%。 but no luck. 但没有运气。

UPDATE : Its actually the front end meaning for the user, at the back end i use Analysis Stored Procedures, "IsLike" for this. 更新:它实际上是对用户的前端含义,在后端我为此使用Analysis Stored Procedures,“ IsLike”。 Query is something like this : { WITH MEMBER [Measures].[Search] AS IIF( [ASSP].[IsLike] ([Calculation].[Calculation].CurrentMember.Properties('MEMBER_CAP‌​‌​TION'),'%50%%')} 查询是这样的:{WITH MEMBER [Measures]。[Search] AS IIF([ASSP]。[IsLike]([Calculation]。[Calculation] .CurrentMember.Properties('MEMBER_CAP‌ÂTION'),'% 50 %%')}

Thanks 谢谢

If I understand your question correctly, then you are using the ASSP (Analysis Stored Procedures) IsLike method, and want to know how you can escape a % in the like template so that it is searched for literally. 如果我正确理解了您的问题,那么您正在使用ASSP(分析存储过程)IsLike方法,并且想知道如何在相似模板中转义% ,以便从字面上搜索它。 Looking at the source code ( http://asstoredprocedures.codeplex.com/SourceControl/latest#ASSP/StringFilters.cs , method LikeToRegEx ), I do not see an easy way to achieve this. 看一下源代码( http://asstoredprocedures.codeplex.com/SourceControl/latest#ASSP/StringFilters.cs ,方法LikeToRegEx ),我看不到实现此目的的简便方法。 In this method, a percent is replaced unconditionally by ".*" . 在此方法中,百分比无条件地由".*"代替。 What you could do is download the ASSP source code and change this method to allow escaping the percent eg with "[%]" which would work in the SQL Server relational engine like . 您可以做的是下载ASSP源代码并更改此方法,以允许转义百分比,例如,使用"[%]"可以在SQL Server关系引擎( like E. g. 例如 you could add after the 您可以在

sb.Replace("[.]", @"_");

another line 另一条线

sb.Replace("[\.]", @"%");

which would revert the overly aggressive replace of [%] with [.*] . 这将恢复[%]过度用[.*]代替。 Then you would compile this and re-deploy. 然后,您将对此进行编译并重新部署。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM