Author |
Topic |
neo_bagsjol
Starting Member
6 Posts |
Posted - 2014-01-26 : 23:12:18
|
Hello Expert Good day, i would like to ask help for the this scenario,here it goes.. i have two columns which are start date and terms..when the user enter a date for example January 1,2014 and the term is 5 months to pay then the script will generate 5 months from the start date specified and every month should start 1 depends on the day selected..below should be the sample output:===========================January 1,2014Februay 1,2014March 1,2014April 1,2014May 1,2014============================how can i achieved this on stored procedure. Please helpthanks in advance |
|
stepson
Aged Yak Warrior
545 Posts |
Posted - 2014-01-27 : 01:30:16
|
[code]declare @dStartDate as datedeclare @iNoOfMonth as intset @dStartDate ='20140115'set @iNoOfMonth=5select @dStartDate=DATEADD(m,DATEDIFF(m,0,@dStartDate),0) --now it's 2014-01-01;WITH aCTEAS( SELECT @dStartDate as FirstOfMonth,1 as lvl UNION ALL SELECT DATEADD(m,1,FirstOfMonth),lvl+1 FROM aCTE WHERE aCTE.lvl<@iNoOfMonth)SELECT FirstOfMonth FROM aCTE[/code]SCe-am pe mine am si-n dulap, cand ma-mbrac zici ca ma mutsabinWeb |
|
|
stepson
Aged Yak Warrior
545 Posts |
Posted - 2014-01-27 : 01:30:40
|
the output2014-01-012014-02-012014-03-012014-04-012014-05-01 Ce-am pe mine am si-n dulap, cand ma-mbrac zici ca ma mutsabinWeb |
|
|
neo_bagsjol
Starting Member
6 Posts |
Posted - 2014-01-27 : 01:48:52
|
thank you very much stepson for the script..question how about if i'm going to change the date instead of date 1 specified..i want to select another date like for example Jan 24,2014 so the output will be..Jan 24,2014Feb 24,2014and soon..thanks |
|
|
stepson
Aged Yak Warrior
545 Posts |
Posted - 2014-01-27 : 01:58:47
|
hello,comment this lineselect @dStartDate=DATEADD(m,DATEDIFF(m,0,@dStartDate),0) --now it's 2014-01-01 SCe-am pe mine am si-n dulap, cand ma-mbrac zici ca ma mutsabinWeb |
|
|
neo_bagsjol
Starting Member
6 Posts |
Posted - 2014-01-27 : 02:12:20
|
WoW its working...another one i notice that Feb has no 30 its only 28 days and when i change date into 30 from January the output is look like this..Jan 30,2014Feb 28,2014March 28,2014April 28,2014and soon..its copies the date from Feb how can i prevent that? it should beJan 30,2014Feb 28,2014March 30,2014 April 30,2014and soon.thanks |
|
|
stepson
Aged Yak Warrior
545 Posts |
Posted - 2014-01-27 : 02:15:30
|
[code];WITH aCTEAS( SELECT @dStartDate as FirstOfMonth,1 as lvl UNION ALL SELECT DATEADD(m,lvl,@dStartDate),lvl+1 FROM aCTE WHERE aCTE.lvl<@iNoOfMonth)SELECT FirstOfMonth FROM aCTE[/code]this line should be change[code]SELECT DATEADD(m,1,FirstOfMonth),lvl+1with SELECT DATEADD(m,lvl,FirstOfMonth),lvl+1[/code]SCe-am pe mine am si-n dulap, cand ma-mbrac zici ca ma mutsabinWeb |
|
|
neo_bagsjol
Starting Member
6 Posts |
Posted - 2014-01-27 : 02:22:10
|
Your the Man Stepson its work as i expected..thanks a lot i hope this will help also others who seek for an answer..you got two thumbs up for me.. |
|
|
stepson
Aged Yak Warrior
545 Posts |
Posted - 2014-01-27 : 02:22:29
|
with welcomeSCe-am pe mine am si-n dulap, cand ma-mbrac zici ca ma mutsabinWeb |
|
|
|