Occasionally the need arises to build dynamic CAML queries in order to get items from a SharePoint list. This was the case recently while delivering a solution for a customer. In my solution I used a combination of controls including ASP .NET and SharePoint controls.
In my solution I created a form which posted to the server the values which were to be used for the query. For the solution I decided to use a string builder function and a string array to store the values, and then I looped through the results and used those which contained values to build the CAML query.
Read the article