How to count the Number of Records

  • HI,

    I have table student

    st_id , st_name, act_date

    1 james 2/2/2012

    2 albert 2/4/2012

    3 johnson 30/1/2012

    4 hitler 2/2/2012

    you can see the first record the act_date is 2nd Feb 2012.

    Addign one month to Every record.

    Ex:

    Today date is 23rd Feb 2012, see the first record 2nd Feb 2012.

    2nd Feb 2012+adding One Month=> 3rd March 2012.

    When i logined into my web site (23rd Feb 2012) , it has to show the count Zero.

    When i logined into my web site (3rd March 2012), it has to show the count=2 i.e the 1st record and 4th record.

    Same process wlll have to follw to other records.

    How to write a Query to count that records based on that condition adding after one month to the record.

    Thanks,

  • I am bit lost here... is your requirement to find the count of rows that are exactly older than 30 days?

    If yes, then use this

    DECLARE @Dateparam DATETIME = '3-MAR-2012'

    SELECT @Dateparam = DATEADD(D,-30,@Dateparam)

    SELECT COUNT(*)

    FROM Students

    WHERE act_date = @Dateparam

  • The answer is possible after:

    http://www.sqlservercentral.com/articles/Best+Practices/61537/

    _____________________________________________
    "The only true wisdom is in knowing you know nothing"
    "O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!":-D
    (So many miracle inventions provided by MS to us...)

    How to post your question to get the best and quick help[/url]

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply