Assuming you are talking about a Multi-select choice field... most likely you will have to create the query each time.
Your code is going to need to determine how many categories are passed in and then generate the CAML. For example, if only ABC is passed your query would be (notice there are no <And>
tags):
<Where>
<Eq>
<FieldRef Name='Category'/>
<Value Type='Choice'>ABC</Value>
</Eq>
</Where>
But if you have three choices passed in via QueryString: ABC, ABD, and ABE you would get (notice the <And>
tags surround each group of two):
<Where>
<And>
<And>
<Eq>
<FieldRef Name='Category'/>
<Value Type='Choice'>ABC</Value>
</Eq>
<Eq>
<FieldRef Name='Category'/>
<Value Type='Choice'>ABD</Value>
</Eq>
</And>
<Eq>
<FieldRef Name='Category'/>
<Value Type='Choice'>ABE</Value>
</Eq>
</And>
</Where>
Edit:
static void Main(string[] args)
{
try
{
string[] parameters = { "ABC", "DEF", "GHI" };
string camlQuery = CreateCAMLQuery(parameters);
Console.WriteLine(camlQuery);
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
Console.WriteLine("Press any key...");
Console.ReadKey();
}
private static string CreateCAMLQuery(string[] parameters)
{
StringBuilder sb = new StringBuilder();
if (parameters.Length == 0)
{
// perhaps set a default query?
AppendEQ(sb, "all");
}
// "AND" each parameter to the query
for (int i = 0; i < parameters.Length; i++)
{
AppendEQ(sb, parameters[i]);
if (i > 0)
{
sb.Insert(0, "<And>");
sb.Append("</And>");
}
}
sb.Insert(0, "<Where>");
sb.Append("</Where>");
return sb.ToString();
}
private static void AppendEQ(StringBuilder sb, string value)
{
// put your field's internal name in place of Category
sb.Append("<Eq>");
sb.Append("<FieldRef Name='Category'/>");
sb.AppendFormat("<Value Type='Choice'>{0}</Value>", value);
sb.Append("</Eq>");
}