 |
Filtering Numeric Fields |
|
|
|
As done for strings, if a field holds both numeric and
null values, to find out whether a field holds a null value, apply the
IS NULL expression to its condition.
Here is an example:
|
SELECT [Shelf #], Title, [Year]
FROM Videos
WHERE [Year] IS NULL;
GO
Unlike strings, number-based fields use all Boolean
operators supported both by ISO SQL anbd Transact-SQL. They are:
| Operation |
Used to find out whether |
| = |
A field holds a certain numeric value |
| <> or != |
A field doesn't hold a certain numeric value or a field has a
value different from a certain numeric value |
| < |
A field's value is lower than a certain numeric value |
| <= or !> |
A field's value is lower than or is equal to a certain numeric
value or a field's value is not greater than a certain numeric value |
| > |
A field's value is greater than a certain numeric value |
| >= or !< |
A field's value is greater than or is equal to a certain numeric
value or a field's value is greater than or is equal to a certain
numeric value |
Here is an example:
void btnSelectClick(object sender, EventArgs e)
{
using (SqlConnection connection =
new SqlConnection("Data Source=(local);" +
"Database='VideoCollection1';" +
"Integrated Security=yes;"))
{
SqlCommand command =
new SqlCommand("SELECT ALL * FROM Videos " +
"WHERE [Length] > 125;",
connection);
connection.Open();
command.ExecuteNonQuery();
SqlDataAdapter sdaVideos = new SqlDataAdapter(command);
BindingSource bsVideos = new BindingSource();
DataSet dsVideos = new DataSet("VideosSet");
sdaVideos.Fill(dsVideos);
bsVideos.DataSource = dsVideos.Tables[0];
dgvVideos.DataSource = bsVideos;
}
}
This would produce:

|
The Negativity or Opposite of a Numeric
Comparison
|
|
There are various ways you can find the negation of a
number-based comparison. As seen previously, to negate a comparison, you can
precede the expression with the NOT operator. Otherwise, by
definition, each Boolean operator has an opposite. They are:
| Operation |
Opposite |
| Primary |
Also |
Primary |
Also |
| = |
<> |
!= |
| <> |
!= |
= |
| < |
!< |
>= |
| <= |
> |
!> |
| > |
!> |
<= |
| >= |
< |
!< |
Based on this, to find the negativity of a comparision,
you can use the opposite operator.
|
|