Solved

select statement

Posted on 2008-10-22
7
183 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

863 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

22 Experts available now in Live!

Get 1:1 Help Now