Tuesday, March 27, 2012

Date query question!

Hi,

I've a problem with making a query. I need to get out a result where a date
for example 25-02-05 is in a table.
The problem is that the dates in the table are old like 25-02-03. So is
there a sollution where I only need the day and month to get the result?

Thanks,
Fred"news.wanadoo.nl" <fabfreddy@.zonnet.nl> wrote in message
news:421f7fda$0$32252$afc38c87@.news.wanadoo.nl...
> Hi,
> I've a problem with making a query. I need to get out a result where a
> date for example 25-02-05 is in a table.
> The problem is that the dates in the table are old like 25-02-03. So is
> there a sollution where I only need the day and month to get the result?
> Thanks,
> Fred

select *
from dbo.MyTable
where right(convert(char(8), datecol, 112), 4) = '0225'

select *
from dbo.MyTable
where day(datecol) = 25 and month(datecol) = 2

These will return multiple rows, of course, if you have 20030225, 20020225
etc in your table - I don't know if that's what you want or not. Also check
out DATEPART() in Books Online.

Simonsql

No comments:

Post a Comment