Thursday, January 17, 2013

find out what are the days available in two different dates

declare

@startdate varchar(30)

declare

@enddate varchar(30)

Declare

@init int

Declare

@count int

select

@startdate='2013-01-18 00:00:00.000',@enddate='2013-01-25 00:00:00.000',@init=0

select

@count=DATEDIFF(day,@startdate,@enddate)

if

OBJECT_ID('#tab')>0

drop

table #tab

create

table #tab(sno int identity(1,1),[date] datetime)

while

@init<=@count

begin

insert

into #tab([date])

select

dateadd(day,@init,@startdate)

select

@init=@init+1

end

select

* from #tab

No comments:

Post a Comment