views:

368

answers:

2

Is there "nice" way to create a CAML query for SharePoint that does something like this?

SELECT *
FROM table
WHERE Id IN (3, 12, ...)

Or am I stuck with a nightmare of nested <Or> nodes?

+2  A: 

FullTextSqlQuery

It is possible to search MOSS using SQL statements, using the FullTextSqlQuery class. I have no experience of using this class personally. These articles may be of use:

YACAMLQT

Alternatively, there is also YACAMLQT (Yet Another CAML Query Tool) which allows you to create SharePoint CAML queries using a T-SQL syntax.

LINQ to SharePoint

If you are up to speed with LINQ, then the LINQ to SharePoint project provides a tool to query SharePoint lists using the LINQ syntax. Please note, this tool is still in the alpha testing phase, so it may not be production ready.

U2U CAML Query Builder

If you are working with CAML queries, I would recommend using the U2U CAML Query Builder for SharePoint (2003 and 2007) tool to build up your CAML queries. The tool allows you to build up your query string, and to execute it against the target list, using a point-and-click interface, as shown below.

U2U CAML Query Builder for SharePoint in action

Of the above four methods, I can recommend the U2U CAML Query Builder, having used it almost daily over the last 6 months. It also appears to be the most widely used CAML tool in the SharePoint community .

Note, if you are building the CAML queries in code, then I recommend that you take a look at the CAML.NET project on CodePlex, which provides "a set of .NET language-based tools for creating dynamic, reusable CAML query components".

MagicAndi
Didn't know about CAML.NET. May need to use that in the future. I did something similar with XElements to generate the necessary `<Or>`s.
Rfvgyhn
+1  A: 

NO, you'll need to deal with nested OR tags; these are supported query instructions on CAML

Maybe CAML.NET can help you in your quest.

Rubens Farias