Solved

sql query between not working

Posted on 2011-09-02
3
146 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
ID: 36472273
Hi,
What error do you get?
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 36472314
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
ID: 36472425
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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Restore Script - Syntax Error 8 106
SQL query to summarize items per month 5 75
ISDATE() not working properly on my table? Any suggestions. 7 44
Replication failure 1 19
I've encountered valid database schemas that do not have a primary key.  For example, I use LogParser from Microsoft to push IIS logs into a SQL database table for processing and analysis.  However, occasionally due to user error or a scheduled task…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…

713 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