• Dear friends ,

    Thank you for suggesting all the alternate ways to solve the problems.

    One of my friends suggested me the following ways which is similar the way you explained.

    He suggested the following steps.

    1> Instead the hardcore 15 days value we can pass the number of days to stored procedure.

    2> Now that would be done in the following query.

    the query may look like this

    select * from person where datediff(d,getdate(),dob)> @nos_of_days

    @nos_of_days -> the passed value of days to be found out could be 15,12,30,40 etc.

    The problem is that the SQL SERVER 2005 stores in yy/dd/mm format.

    So when our dob which will give larger amount of diffreence like 12/12/1999 and currentdate i.e. 27/3/2009 which could be result in higher days like greater then 1500 days, not valid.

    The solution is the append the current year i.e. 2009 for all the dob fields such that we can find out only the difference between month & date , years are made same so we don't have problem in line. we have to get it in similar format the query may look like this .

    select convert(varchar(12),dob+cast(year(getdate())as varchar),105) from person

    3> substract currentdate using (GETDATE()) from that modified dob whose current year is same.

    (well obvious that we had made it same in step two)

    4> check if it's greater then our desired values , the query may look like this.

    select * from person where datediff(d,getdate(),dob)< @nos_of_days

    well this is nice one based on the magic of CONVERT & CAST functions .

    I had tried the following queries to make the working idea clear in mind.

    select cast(year(getdate())as varchar) from person

    select cast(year(dob)as varchar) from person

    output (all the current year)

    2009

    select convert(varchar(12),dob,105) from person

    -- to convert in dd/mm/yy format which will be used for Comparing the dates , the output is now same just giving the year nothing else.

    27-03-2009

    Now main problem is

    select convert(varchar(12), dob+cast(year(getdate())as varchar),103) from person

    /* output

    28/03/2118

    as you can see the desired output was just to append the 2009 on the dob field but it's not working.

    So could you ,please suggest the steps to overcome for implement the stored procdeure, Please.

    Thanks in advance.