ORELSE?

  • Thread starter Thread starter Nak
  • Start date Start date
N

Nak

Hi there,

I am trying to perform date searching in a database via SQL commands. I
want to be able to retrieve items before, equal, and after a sepecific date.
The only way I can think of doing the before or after comparrisons are via
VB.NET's "ORELSE" keyword, is there an SQL equivilent?

For example

YEAR(dateissued)<2004 ORELSE MONTH(dateissued)<10 ORELSE
DAY(dateissued)<12

This way it would jump out when the largest denominator (so to speak) is
before the sepcified date. Though the above does not work (as I suppose
ORELSE isn't an SQL operator?). Anyway, does anyone know of a quick way to
achieve this? Thanks loads in advance, much appreciated!

Nick.
 
Nak said:
I am trying to perform date searching in a database via SQL commands. I
want to be able to retrieve items before, equal, and after a sepecific date.
The only way I can think of doing the before or after comparrisons are via
VB.NET's "ORELSE" keyword, is there an SQL equivilent?

For example

YEAR(dateissued)<2004 ORELSE MONTH(dateissued)<10 ORELSE
DAY(dateissued)<12

This way it would jump out when the largest denominator (so to speak) is
before the sepcified date. Though the above does not work (as I suppose
ORELSE isn't an SQL operator?). Anyway, does anyone know of a quick way to
achieve this? Thanks loads in advance, much appreciated!

Indeed ORELSE isn't a SQL operator. OR is, however.

Wouldn't it be easier just to specify a single DateTime and use the <=
operator though?
 
Hi Jon,

Forgive me but I do not know all about SQL, only a base understanding.
Currently if I look in the datagrid that is returned to me the date appears
as

"13/09/2004"

If I look at the database in Access it appears as,

"13/09/2004 10:30:00"

I've tried editing the database in Access to remove the times but still
if I use the WHERE statement

WHERE dateissued<'13/09/2004'

I still get returned *all* dates in the database. Am I missing CONVERT
or CAST statements??

Nick.
 
Nak said:
Forgive me but I do not know all about SQL, only a base understanding.
Currently if I look in the datagrid that is returned to me the date appears
as

"13/09/2004"

If I look at the database in Access it appears as,

"13/09/2004 10:30:00"

I've tried editing the database in Access to remove the times but still
if I use the WHERE statement

WHERE dateissued<'13/09/2004'

I still get returned *all* dates in the database. Am I missing CONVERT
or CAST statements??

Don't put the date directly in the SQL at all. Use database parameters.
That way you can use an actual DateTime, and any conversion gets done
in the provider or the database itself.

See OleDbCommand.Parameters or OdbcCommand.Parameters (depending on
what you're using) for more information.
 
Thanks Jon,

I had been doing the command in a weird way, so now I have changed it
all to enable me to use the parameters like I do in an "INSERT" statement
and the like. Thanks loads for your help! :-)

Nick.
 
Mr Nak,

Is that not a strange thing you ask even when it was a vallid command

Everything what is before 2004
And when not what is before month 10
And when not what is before day 12

The same as date < Now.date

Something as
Select * from my table where tabledatefield < @now

and that will be than extra using the oledb commandparameters

da.SelectCommand.Parameters.Add("@now", OleDb.OleDbType.Date).Value =
Now.Date

I hope this helps

Cor
 
Hi Cor,

The problem was that I was propegating a data grid in a completely
different way, and when I tried to add parameters to the object I simply got
an exception throw. Now I have a method that connects to the database
differently and allows me to do this, I'm new to this ADO.NET stuff so I'm a
little bit rough round the edges! LOL

Anyway, all is sorted now. So Mr Cor, how many newsgroups do you
participate in? You must have a good broad programming knowledge. Good to
see a familiar name anyway! :-)

Nick.
 
Back
Top