Comparison Operators

  • Thread starter Thread starter J Jones
  • Start date Start date
J

J Jones

This may be the wrong newsgroup to be asking about this but I'll ask
anyway..
I have 200 possible conditions expressed as comparisons eg. A <= 100 And A
69. They are stored in an SQL database. I also have a datatable with one
row containing 10 values (A,B,C,D,E,F,G,H,I,J). How can I test the row as a
whole to see if it conforms to none, one or more of the conditions in the
database?
 
This may be the wrong newsgroup to be asking about this but I'll ask
anyway..
I have 200 possible conditions expressed as comparisons eg. A <= 100 And A
row containing 10 values (A,B,C,D,E,F,G,H,I,J). How can I test the row as a
whole to see if it conforms to none, one or more of the conditions in the
database?

Just so nobody is left with a mystery on my question I'll do a bit more
explaining..
The 'Conditions' are comparison strings such as :-

"A <= 100 And A > 69"
"B <= 31 And B > -1"
"C <= -71 And C >= -100"
"A > 69 And B < -19 And C < -19"
"I > 69 And ((H <= -41 And H > -71) Or H <= 19 And H > -11"

Etc. Etc...
There are 200 of these 'Conditions'. I have them as text in a table in SQL
server. I use this column as the pk. for the table.

Then - In my ASP.NET application - I have a Dataset with one row containing
calculated values for A,B,C,D,E,F,G,H,I and J. - i.e:

Column A = 90
Column B = 57
Column C = 36
Column D = 27
Column E = 77
Column F = 42
Column G = 42
Column H = -18
Column I = -100
Column J = 110

What I wanted to know was a way of checking if this array of values meets
any of the 'Conditions' that are stored in the Database table.

The array may or may not meet one or more of the conditions.
I hope my explanation clarifies my question.
 
Hi J,

You could concatenate a select command either on server or in client.
Something like (on client):
"SELECT Count(*) FROM YourColumn WHERE" + condition[0] + condition[1]....
etc
or (on server):
exec ('select Count(*) FROM YourColumn' + yourconditions)
 
Thanks again Miha.
Your reply went over my head unfortunaly.
Is it that I need to test my existing datarow against every 'condition'
that is stored at present in the database. ie Create a new datatable in my
app. populated from the 'conditions' database table. Then plug in the
values of A,B,C etc from my existing datarow and test if the the result is
true or false?
 
Hi J,

J Jones said:
Thanks again Miha.
Your reply went over my head unfortunaly.
Is it that I need to test my existing datarow against every 'condition'
that is stored at present in the database.

Yes. That would be the "client" way.

ie Create a new datatable in my
app. populated from the 'conditions' database table. Then plug in the
values of A,B,C etc from my existing datarow and test if the the result is
true or false?

Not exaxtly. You will create a sql command:
First you should concatenate all of your conditions:
StringBuilder sb = new StringBuilder();
for (int i=0; i<conditionTable.Rows.Count-1; i++)
{
sb.Append(conditionTable["Condition"]);
if (i<conditionTable.Rows.Count-1)
sb.Append(" and ");
}

string sqlCommandStr = "SELECT * FROM YourTableName WHERE " + sb.ToString();
// execute reader or fill with the command above

HTH
 
Back
Top