0

I tried to use the SelectQueryBuilder for the following query,but it is not coming exactly as it should be.

I want a Query String Like this

SELECT * FROM CustomerData WHERE (CustomerType = 'SPC3' OR CustomerType = 'SPC2' OR CustomerType = 'SPC5') AND Country='UK'

but what I am getting is

SELECT * FROM CustomerData WHERE ((CustomerType = 'SPC3' OR CustomerType = 'SPC3') AND (CustomerType = 'SPC2' OR CustomerType = 'SPC2') AND (CustomerType = 'SPC5' OR CustomerType = 'SPC5')) AND country='UK'

My code is:

var query = new SelectQueryBuilder();
query.SelectFromTable("CustomerData");
query.SelectAllColumns();
query.AddWhere("CustomerType", Comparison.Equals,"UK");

foreach (var selectedCustomerType in selectedCustomerList)
{
WhereClause whereClause = query.AddWhere("CustomerType", Comparison.Equals, selectedCustomerType);
whereClause.AddClause(LogicOperator.Or, Comparison.Equals, selectedCustomerType);
}

String queryStatement = query.BuildQuery();

How can I add LogicOperator.Or in the statement itself ?

Thanks.

D'Arcy Rittich
  • 167,292
  • 40
  • 290
  • 283
nikn8
  • 1,016
  • 8
  • 23

1 Answers1

0

Try using the AddWhere method overload. it has level parameter to decide what level of where nesting the condition goes to

I never had the need to try the levels so let me know what turns up with you and I'll try to help more :)

Happy coding

Katia
  • 679
  • 2
  • 15
  • 42