Click here to Skip to main content
15,895,011 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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,
Posted
Comments
Sarvesh Kumar Gupta 22-Feb-12 22:09pm    
When you login into web site on 3rd march then you write count 2 but should be 3. Record 1, 3, 4. i m right?

SQL
Select RecordCount=count(st_id) 
from student 
where datediff(day,dateadd(Month,1,act_date),getdate())=0

Please let me know if the above query doesn't match what you want.
 
Share this answer
 
Comments
Sarvesh Kumar Gupta 22-Feb-12 22:10pm    
not 0, should be less from getdate()
Hi, use below query

SQL
Select RecordCount=count(st_id) 
from student 
where dateadd(Month,1,act_date) <= getdate() 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900