?
Solved

SQL select statement where date = '1/2/2008'

Posted on 2011-03-10
4
Medium Priority
?
330 Views
Last Modified: 2012-05-11
For the life of me I can't figure this one out. I am trying to query a database and return records for a single day, btu keep getting erroneus results and now I see why. How can I make this work?

select *
from [userTable]
where myDate>= '1/2/2008'
AND myDate<='1/2/2008'

myDate looks like this 2008-01-02 10:55:40.0000000

There has got to be an easier way. lol.

thanks.

Jim
0
Comment
Question by:JimmyDeuce
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 32

Assisted Solution

by:Ephraim Wangoya
Ephraim Wangoya earned 200 total points
ID: 35101364

declare @MyDate DateTime
set @MyDate = '1/2/2008'

select *
from [userTable]
where myDate >= @MyDate
AND myDate < DATEADD(DD, 1, @MyDate)
0
 
LVL 41

Accepted Solution

by:
Sharath earned 1500 total points
ID: 35101436
you have to provide the time part as well.
select * 
from [userTable] 
where myDate>= '1/2/2008'
AND mydate <='1/2/2008 23:59:59'

Open in new window

0
 
LVL 143

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 100 total points
ID: 35105855
how to hande date/time correctly: read this article
http://www.experts-exchange.com/A_1499.html
0
 
LVL 5

Assisted Solution

by:NARANTHIRAN
NARANTHIRAN earned 200 total points
ID: 35106181
Try using the following query in the following format.
select *
from [userTable]
where myDate>= '2008-02-01'
AND myDate<='2008-02-01'

i think this may help u..
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to writing scripts for a Client/Server computing environment it is essential to consider some way of enabling the authentication functionality within a script. This sort of consideration mainly comes into the picture when we are dealin…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question