Showing posts with label datetimes. Show all posts
Showing posts with label datetimes. Show all posts

Thursday, March 29, 2012

Comparing to DateTimes in SQL-Select-Statement when one Date can be null

Hello!

I have a field "End" in my database that is mapped as DateTime and allows nulls. Now I want to do a SQL-Select (in a SqlDataSource) like

SELECT * FROM My_Table Where (([End] = @.EndDate) OR ([End] =null))


@.EndDate is a valid DateTime, but the second OR condition doesn't work.

What is the best way to check if the [End]-field is empty or null?

Thank you very much!

Try this: [End] IS NULL

Sunday, March 11, 2012

Compare datetimes

Hi

I need to retrieve data from a table comparing datetimes. I mean I've a
table with a datetime data and I'll need to retrieve rows with date time
> now and date time < now + 5 minutes...

Is this posible ? Which is the best / easy way ?

Thanks in advance

J"Javier" <jleyba@.manresa.net> wrote in message
news:cu8frg$d8m$1@.news.ya.com...
> Hi
> I need to retrieve data from a table comparing datetimes. I mean I've a
> table with a datetime data and I'll need to retrieve rows with date time
> > now and date time < now + 5 minutes...
> Is this posible ? Which is the best / easy way ?
> Thanks in advance
> J

Check out DATEADD() in Books Online.

select col1, col2, ...
from dbo.MyTable
where dtcol > getdate()
and dtcol < dateadd(mi, 5, getdate())

Simon|||On Mon, 07 Feb 2005 20:34:05 +0100, Javier wrote:

>Hi
>I need to retrieve data from a table comparing datetimes. I mean I've a
>table with a datetime data and I'll need to retrieve rows with date time
> > now and date time < now + 5 minutes...
>Is this posible ? Which is the best / easy way ?

Hi Javier,

SELECT Column1, Column2, ...
FROM MyTable
WHERE MyDatetimeColumn > CURRENT_TIMESTAMP
AND MyDatetimeColumn < DATEADD(minute, 5, CURRENT_TIMESTAMP)

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)