简体   繁体   中英

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

How do i escape "%" character in a dynamic MDX. I want "%" to be treated as a literal and not a wild card in 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. 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.

Now, i dont get correct result when query is like :

Calculation Contains 50%

Here, % is treated as wild card and anything containing "50" is shown. 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. Query is something like this : { 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. 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. 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 . 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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