Solved

select statement

Posted on 2008-10-22
7
185 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

809 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