none
access data from MS Sql server 2000 RRS feed

  • Question

  • Hi, I'm using VB .net 2003 and  MS SQL server 2000. I have a table "student" which has two fields.

    Name --- varchar, --- contains name of the student

    Sdate--- datetime --- contains the server  system date

     

    I'm inserting values in the table like this:

    insert into student (NAME, SDATE) values ('abcd', getdate())

    it works fine.

     

    Student table looks like:

    Name                            Sdate

    -------------------------      -----------------------

    abcd                            6/27/2007 9:34:26 PM

    xyz                               6/28/2007 10:10:45 AM

    ......

    Now,

    I want to fetch all the Names of students entered in last 6 months from current System date. What will be the SQL query for that?

    Thursday, June 28, 2007 7:06 PM

Answers

  • It will be something like

     

    SELECT  [NAME], [SDATE] WHERE [SDATE] BETWEEN DATEADD(m, -6, GETDATE()) AND GETDATE()

     

     

    Friday, June 29, 2007 10:37 AM
    Moderator

All replies

  • U apply the function datediff and include the format mm or m to get no.of months and apply the condition display the data

    i think u got it

    Baba

    Friday, June 29, 2007 8:11 AM
  • Give me the code please.
    Friday, June 29, 2007 10:31 AM
  • It will be something like

     

    SELECT  [NAME], [SDATE] WHERE [SDATE] BETWEEN DATEADD(m, -6, GETDATE()) AND GETDATE()

     

     

    Friday, June 29, 2007 10:37 AM
    Moderator