Click here to Skip to main content
15,895,011 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
[Image]

i have fields in database i want user can search in all fields or any combination of fields
and but the opertors he or she want (AND,OR) but it make me confused in generating code
or query

notice :user can search in from one fields up to all fields
but he must enter operator before any fields he want to search

this my standard query
String SqlStatment = "SELECT * FROM [View_AnIssues]


when user choose from thfirst dropdownlist say (And) and the second (Or)

then MyQuery became
SQL
String SqlStatment = "SELECT * FROM [View_AnIssues] where numField=value AND YearField =Value2 Or NeedsField=Value2;


i hope to be able to describe the case

pleaze i need help
Posted
Comments
OriginalGriff 25-Sep-12 10:26am    
And what is your problem?
We understand the situation, but what are you having difficulty doing / understanding?
nagiub2007 25-Sep-12 10:40am    
i cannot generate the sql querey
or it's logic

1 solution

Your problem is that you are 'confused'. Since this problem is not technical or related to code, I can't help you on this. And yes, regarding the code, I can suggest you to use parenthesis to enclose the operands and operators wherever you feel to make the code readable. Also remember that the OR operator takes precedence over AND


For. eg.
C#
String SqlStatment = "SELECT * FROM [View_AnIssues] where (numField=value AND YearField =Value2 )Or NeedsField=Value2;
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900