Solved

select statement

Posted on 2008-10-22
7
184 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

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…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
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…

778 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