Error in displaying days in a month

Posted by Klbaiju under Sql Server on 12/13/2014 | Points: 10 | Views : 323 | Status : [Member] | Replies : 1
Hi,

I want to display days in a particular month.

following query displays that in 30 days .my requirement is to display from 1 to 15 and 15 to 30 or 31.

this is my query

declare @dte as  datetime ='2013-07-15'

--declare @dte as datetime
--declare @tdate as datetime ='2013-07-01'

declare @StDt as Datetime = DATEADD(dd,-(DAY(GETDATE())-1),@dte)
declare @EnDt as datetime = DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,@dte)+1,0))
Declare @Cnt as int = datepart(dd,@EnDt)
Declare @inc as int = 0
Create table #temp (Month_date datetime)
while @inc < @cnt
begin
insert into #temp
select DATEADD(dd, @inc, DATEADD(dd,-(DAY(@dte)-1),@dte))
set @inc = @inc + 1

end
select * from #temp
drop table #temp


how to solve it.

Regards
Baiju




Responses

Posted by: Bandi on: 12/15/2014 [Member] [MVP] Platinum | Points: 25

Up
0
Down
what is problem you are facing in the above query?

please explain clearly for quick response....

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Klbaiju, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response