Solved

select statement

Posted on 2008-10-22
7
179 Views
Last Modified: 2012-05-05
I am using MS-SQL 2000. My column Date_time where it stamps date and time,   10/20/2008 12:49:47 PM.
I have a calendar where user can select a date. Sample 10/20/2008.  My select statement I have this  : select *from mytable where date_time between convert(datetime,  '10/20/2008') and convert(datetime, '10/22/2008' )  < this does not work.  I need help.
0
Comment
Question by:VBdotnet2005
7 Comments
 
LVL 59

Expert Comment

by:Kevin Cross
ID: 22781354
The above statement should work as the converted datetime should be:
2008-10-20 00:00:00

Which will then make your date_time of 2008-10-20 12:49:47 fall within the range.

Please provide your exact code using from the ASP.NET page to construct the query.
0
 
LVL 2

Accepted Solution

by:
BobTheViolent earned 500 total points
ID: 22781353
I think it is just because of a missing space after the *.  It worked for me when I changed that.

Try
select * from mytable where date_time between convert(datetime,  '10/20/2008') and convert(datetime, '10/22/2008' )
0
 
LVL 59

Expert Comment

by:Kevin Cross
ID: 22781367
I agree.  Since I don't have your table data, I didn't use your query above and worked for me perfectly.  Therefore, if that is not a type-o, then please post your exact code as suggested since the SQL syntax is valid.
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 5

Expert Comment

by:eridanix
ID: 22784148
Hi,

I mean, that you have changed days and months in you date strings.
Try this:


select * 

from mytable 

where date_time between convert(datetime,  '20/10/2008') and convert(datetime, '22/10/2008' )

Open in new window

0
 

Author Comment

by:VBdotnet2005
ID: 22788747
One small problem I have is. When I do this
select * from mytable where date_time between convert(datetime,  '10/22/2008') and convert(datetime, '10/23/2008' )
I received the result on 10/22 only, nothing on the 23rd.

But if I do this

select * from mytable where date_time between convert(datetime,  '10/22/2008') and convert(datetime, '10/24/2008' )

I received the result from 10/22 to 10/23. Strange. Any ideas?
0
 
LVL 59

Expert Comment

by:Kevin Cross
ID: 22788887
See my first comment.  You are creating date at midnight, so you will only get data between 10/22 12:00:00 AM and 10/23 12:00:00 AM which is pretty much just 10/22.
0
 

Author Comment

by:VBdotnet2005
ID: 22788953
thank you
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

760 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now