none
MS SQL SERVER Date comparison RRS feed

  • Question

  • Hi, I'm using VB .net 2003 and MS SQL Server 2000. I've a table 'Student' which contains one field SDATE-- DateTime data type.

     

    I have two String variables in VB .net code

    Dim d1 as String

    Dim d2 as String

     

    d1 and d2 contain date in String format (mm/dd/yyyy), [user inputs]

    d1="07/01/2007"

    d2="07/09/2007"

     

    I want to select  all the fields from Student table where SDATE between 07/01/2007 and 07/09/2007. I have tried the following query, but its not working:

    SELECT * FROM STUDENT WHERE [SDATE] BETWEEN  7/4/2007 AND 7/7/2007

     

    what should be the proper sql query for the same?

    Monday, July 9, 2007 2:49 PM

Answers

All replies

  • Put ticks around the date values:

    SELECT * FROM STUDENT WHERE [SDATE] BETWEEN  '7/4/2007' AND '7/7/2007'
    Tuesday, July 10, 2007 7:20 AM
  • U place the values in single code
    Tuesday, July 10, 2007 8:35 AM
  • Hi, it works fine. But I need to do little more. In the follwing query

    SELECT * FROM STUDENT WHERE [SDATE] BETWEEN  '7/4/2007' AND '7/7/2007'

    it searches upto 7/6/2007 and not upto 7/7/2007. I want the records of 7/7/2007 starting from 7/4/2007.

    What will be the query?

    Wednesday, July 11, 2007 11:44 AM