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
 General SQL Server Forums
 New to SQL Server Programming
 Query Table for a specific date

Author  Topic 

raysefo
Constraint Violating Yak Guru

260 Posts

Posted - 2011-06-27 : 12:28:32
Hi,
I am using MS SQL Server 2008 and I would like to query a table for a date. (27/06/2011)
How can I query as follows?

Select * from table1 where mydate = 27/06/2011

Best Regards.

Seventhnight
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2011-06-27 : 12:31:33
need ' marks:

Select * from table1 where mydate = '27/06/2011'



Corey

I Has Returned!!
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2011-06-27 : 13:00:00
I would prefer WHERE mydate = '20110627'


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

Dasman
Yak Posting Veteran

79 Posts

Posted - 2011-06-27 : 14:24:59
You can also try SQL's IN Operator.
SELECT *
FROM table_name
WHERE column_name IN (value1,value2,...)

Dasman

==========================
Pain is Weakness Leaving the Body.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-06-29 : 03:59:10
Also read this to know why you should not use regional date formats
http://beyondrelational.com/blogs/madhivanan/archive/2010/06/03/understanding-datetime-column-part-ii.aspx

Madhivanan

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

- Advertisement -