Solved

sql query between not working

Posted on 2011-09-02
3
140 Views
Last Modified: 2012-05-12
Hello experts,
I am working with sql server 2005.
I am trying to execute a query like  "SELECT username,date, convert(datetime, actionDate,3)  FROM logs WHERE ID>0" and that is working fine.

when i try it with  "SELECT username,date, convert(datetime, actionDate,103)  FROM logs WHERE convert(datetime, actionDate,103)  > '01/06/2010'" then i get an error.

i get error for the between statement also.
The records exist in the database.
Where do i missing something here?
Thanks in advance.
0
Comment
Question by:Ludo_Dirckx
3 Comments
 
LVL 5

Expert Comment

by:DavidMorrison
Comment Utility
Hi,
What error do you get?
0
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
Comment Utility
it's time to read this article:
http://www.experts-exchange.com/A_1499.html

in short:
>convert(datetime, actionDate,103)  > '01/06/2010'
is actiondate a date field or a text field?
if it's date:
actionDate > convert(datetime,  '01/06/2010' ,103)  

if it's text:
convert(datetime, actionDate,103) > convert(datetime,  '01/06/2010' ,103)  

hope this helps
0
 

Author Comment

by:Ludo_Dirckx
Comment Utility
Hi Experts,
Thanks for the current reply.
Angelll - you got correct, thanks.
It is a date field and working perfect.
Even i changed the query to  
 Dim rdrQuery As String = "SELECT * FROM logs WHERE actionDate between convert(datetime,  '29/06/2011' ,103) and convert(datetime,  '29/07/2011' ,103) "
It is working.

Thanks a lot.
Have a nice day.


0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

I am showing a way to read/import the excel data in table using SQL server 2005... Suppose there is an Excel file "Book1" at location "C:\temp" with column "First Name" and "Last Name". Now to import this Excel data into the table, we will use…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

762 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

11 Experts available now in Live!

Get 1:1 Help Now