Click here to Skip to main content
15,890,825 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello hi to all.
I have a problem in selecting some dates.I have a procedure as given below
C#
Create procedure Select_Disurbment_Dates

as
begin

declare @max_Id int,@previousDate datetime,@current_system_date datetime, @Min_disburment_date datetime
set @max_Id=(select MAX(dayopencloseid)  from DayOpenDayCloseInfo
where CollectionByLoanOfficerStatus=1 and DayCloseByAdminStatus=1 )

set @previousDate=(select CenterCollectionDate from DayOpenDayCloseInfo where dayopencloseid=@max_Id)

set @current_system_date=(Select  DATEADD(d,1, @previousDate) as Current_SystemDate )

set @Min_disburment_date=(Select  DATEADD(d,14, @current_system_date)  )
   select @Min_disburment_date as MinDisburment_Date

end

this give me a result as a date

result is 2013-08-21 00:00:00.000

i want to select the next three dates of this date on behalf of any day (may be next three upcoming monday or sunday date which is greater than this dates(i.e. 2013-08-21 00:00:00.000)


How can i find my desired result .. pls Tell me frnds ...
Posted
Updated 16-Aug-13 1:58am
v2

You can acieve that using Common Table Expressions[^]:
SQL
Create procedure Select_Disurbment_Dates
       @inputDate DATETIME   
AS
BEGIN
    --SET DATEFORMAT ymd;

    ;WITH Next3Days AS
    (
	SELECT @inputDate AS MyDate, 0 AS Counter
	UNION ALL
	SELECT DATEADD(dd,1,MyDate), Counter+1 AS Counter
	FROM Next3Days
	WHERE COunter<3
    )
    SELECT CONVERT(VARCHAR(10),MyDate,121) AS MyDate, Counter
    FROM Next3Days
    WHERE Counter>0
END


Result:
CSS
2013-08-22	1
2013-08-23	2
2013-08-24	3


Or use while[^] loop and temporary table ;)
 
Share this answer
 
v5
Comments
GDdixit 16-Aug-13 8:45am    
NO my problem is not that ....

i want to select the next three dates of this date on behalf of any day (may be next three upcoming monday or sunday date which is greater than this dates(i.e. 2013-08-21 00:00:00.000)


as i mention at the end
Maciej Los 16-Aug-13 9:15am    
All you need to do is to define input parameter for stored procedure as i do it in above example using @inputDate.
See my answer now.

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