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 2005 Forums
 Transact-SQL (2005)
 Datetime Issue

Author  Topic 

gangadhara.ms
Aged Yak Warrior

549 Posts

Posted - 2011-06-03 : 04:27:19
Dear All,

I have a table with 5 column out of which one column datatyp is "Datetime"
ID,Country,Dateruled Isactive
Ex: 1,India,Rural,2008-05-15 18:30:00.000 ACTIVE

The datatype for the Dateruled column is of Datetime.

When i query a table using

select * from <tablename> where Dateruled='2008-05-15'

will not result any result set even though we have records.But when i use

select * from <tablename> where Dateruled>='2008-05-15'
It shows all the records above that date.

Could somebody help me to how do we fetch the records for that date.




Thanks,
Gangadhara MS
SQL Developer and DBA

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-06-03 : 04:35:12
that is because the value of that Dateruled is 2008-05-15 18:30 and this is not equal to '2008-05-15'

By specifying '2008-05-15', it means '2008-05-15 00:00:00' which is midnight

if you only want Dateruled for 2008-05-15, specify the where condition like


where Dateruled >= '2008-05-15'
and Dateruled < '2008-05-16'



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -