Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I want to build a CAML query to search for all title fields that do NOT begin with a certain value:

something like this: Where Title NOT BeginsWith 'myvalue'.

How can i do that in my CAML query?

share|improve this question
add comment

4 Answers 4

up vote 1 down vote accepted

as far as I know, this is not possible using caml

you could do it on the results afterwards.

I know it's ugly but I do not know if there is another solution

share|improve this answer
    
True, iterating is terrible and affects performance, out of the question, hope ther is another way –  Zee99 Jun 16 '11 at 14:46
    
Use LINQ to select the correct items maybe> the requested functionality is impossible to do with just CAML –  Colin Jun 16 '11 at 17:01
add comment

You might try adding a calculated column on your list, something to the effect of:

=IF(LEFT([Title], 7)="myvalue", "YES", "NO")

Then you could use the CAML query to check the calculated column for "YES" or "NO".

You might have to adjust the formula above to account for NULL or to test if the overall length (LEN) of the string is longer than the prefix you are checking for, but hopefully you get the idea.

Here is the resource for the forumlas you can use in the calculated column:

http://msdn.microsoft.com/en-us/library/bb862071.aspx

share|improve this answer
add comment

Dependent on the amount of data you are going to query maybe using SP search is a valid approach for you. You can use FullTextSQLQuery to optimize your results and you don't have to filter the results like you have to do with CAML.

share|improve this answer
add comment

You can download the U2U Caml Query application. It is usefull and help you to make caml query easily.

share|improve this answer
    
Although this is a useful tool, it does not help in this case since CAML does not provide an option for NOT BeginsWith. –  Laurie Jun 17 '11 at 5:47
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.