Solved

sql query between not working

Posted on 2011-09-02
3
147 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Sql Query join multiple table and distinct records 7 32
SQL Server Insert where not exists 24 57
SQL Server Configuration Manager WMI Error 11 53
SSMS Imprt data from Excel 7 37
by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
So every once in a while at work I am asked to export data from one table and insert it into another on a different server.  I hate doing this.  There's so many different tables and data types.  Some column data needs quoted and some doesn't.  What …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

734 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