tags:

views:

71

answers:

2

I know that the following is not allowed as a row filter

'canada%.txt' or 'canada*.txt'

and I guess I can rewrite my filter as

file_name like 'Canada%' and file_name like '%.txt' 

should work.

But is there an easier way instead of determing where the % is and spliting the string?

+1  A: 

I don't believe that CHARINDEX is allowed in the filter expression.

You might try to dynamically build the filter string from C# (very much untested, but here's a possible syntax):

//split the original string using the wildcard as the delimiter
string[] f = s.Split('%');

//use the resulting array to build the resultstring
string resultstring = 'file_name like "' + f[0] + '%" and file_name like "%' + f[1] + '"'

//view.RowFilter = resultstring;
LesterDove
I think I forgot to escape some quotes there, but hopefully you get the idea...and hopefully it works for you...
LesterDove
This is what I am doing right now with a function splitting by * or % and rebuilding it. I just wondered if there was a cool linq function that could be applied to the table.
Mike
+1  A: 

Here is the solution that I came up with

    private string CreateRowFilter(string remoteFilePattern)
    {
        string[] pattern = remoteFilePattern.Split(new char[] { '*', '%' });
        int length = pattern.GetUpperBound(0);

        if (length == 0)
        {
            return String.Format("Name = '{0}'", pattern[0]);

        }

        StringBuilder fileter = new StringBuilder(
                 String.Format("Name LIKE '{0}*' ", pattern[0]));

        for (int segment = 1; segment < length; segment++)
        {
            fileter.Append(
                 String.Format("AND Name LIKE '*{0}*' ", pattern[segment]));
        }

        if(String.IsNullOrEmpty(pattern[length]) == false)
        {
            fileter.Append(
                 String.Format("AND Name LIKE '*{0}' ", pattern[length]));
        }

        return fileter.ToString();
    }
Mike