Sometimes it is needed to have a list of dates between two dates that you have supplied in SQL.
Here is the stored procedure to Get list of dates between two dates.
--drop procedure prc_Month
--exec prc_Month '1/1/2013','1/30/2013'
create procedure prc_Month
@fromdate smalldatetime,
@todate smalldatetime
as
begin
create table #date
(
kim_Date varchar(50)
)
insert into #date (kim_Date) Values (@fromdate)
declare @datecount as int
declare @temp as int = 1
set @datecount = DATEDIFF(DAY,@fromdate, @todate)
select @datecount
while @temp<=@datecount
begin
insert into #date (kim_Date) Values (DATEADD(DAY,@temp,@fromdate))
set @temp=@temp+1
end
select * from #date
end
0 comments:
Post a Comment