SQL query  to select the values between dates

Posted on 2006-04-20
Last Modified: 2010-05-18
Hi guys..

I stucked up with one query i think so simple..

I am writing one application in whcih i have to  select the values between  dates..
I am writing the query like this.. in VB

sql="select  file_name from abc where sdate between '" & text1.text  &"' and  '" & text2.text & "'"

where i am getting the values in textboxes from calendar..

but this query is showing errors

 pls let me know this  query how to write the  sql to selecct between dates.. it s urgent

Question by:rajender123
    LVL 142

    Expert Comment

    by:Guy Hengel [angelIII / a3]
    what database?

    Author Comment

    I am using SQL  database and  i am using one table which has  one date column, namely sdate .

    I   want the  values from one table   only

    table has the following cols:-
    file_name, sdate, client_no,name
    LVL 69

    Expert Comment

    by:Éric Moreau
    Hi rajender123,

    if you are using SQL Server, just give your dates as yyyy/mm/dd and it will work

    LVL 4

    Expert Comment

    sql="select  file_name from abc where sdate >= # " & format(text1.text,"mm/dd/yyyy")  &" # and sdate <= # " & format(text1.text,"mm/dd/yyyy")  &"#"

    LVL 142

    Accepted Solution

    In SQL Server, this is the fail-proof method (assuming that the values of text1.text and text2.text are correctly entered as date values):
    sql="select  file_name from abc where sdate between convert(datetime,'" & format(cdate(text1.text) , "YYYY-MM-DD") &"',120) and  convert(datetime,'" & format(cdate(text2.text), "YYYY-MM-DD") & "', 120)"

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
    This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

    760 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

    8 Experts available now in Live!

    Get 1:1 Help Now