Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 DateTime field's question

Author  Topic 

Karander
Starting Member

34 Posts

Posted - 2006-09-24 : 10:49:44
Hi

How to check if a datetime field equals precisely month and year
without using two conditions??

For Instance: November and 2006 year

Thanks :)

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2006-09-24 : 11:20:03
declare @dateFrom datetime, @dateTo datetime
select @dateFrom = '20061101', @dateTo = dateadd(m, 1, @dateFrom)

select *
from YourTable
where YourDateCol between @dateFrom and @dateTo



Go with the flow & have fun! Else fight the flow
blog thingie: http://weblogs.sqlteam.com/mladenp
Go to Top of Page

Karander
Starting Member

34 Posts

Posted - 2006-09-24 : 11:43:11
hey!

Thanks but ...
will not it also include 2006-12-01 date?
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2006-09-24 : 11:49:38
true. forgot about inclusivness of between.
a little fix:

select *
from YourTable
where YourDateCol >= @dateFrom and YourDateCol < @dateTo



Go with the flow & have fun! Else fight the flow
blog thingie: http://weblogs.sqlteam.com/mladenp
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-09-24 : 20:41:58
http://sql-server-performance.com/fk_datetime.asp

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -