February 15, 2012 at 7:59 am
the thing is -:
SELECT count(HolidayDate)as Count,Datename(month,HolidayDate) as Months
FROM tblHoliday_Master
where HolidayDate
between ''+CONVERT(nvarchar, '2012-01-01', 110) +'' and ''+CONVERT(nvarchar, '2012-12-01', 110) +''
GROUP BY Datename(month,HolidayDate) order by Months desc
the data am getting is
5-->jan
2-->feb
;WITH
MY_OTHER_CTE AS
( SELECT TOP (DATEDIFF(mm,
DATEADD(mm,DATEDIFF(mm,0,@DateStart),0), --First of start month
DATEADD(mm,DATEDIFF(mm,0,@DateEnd)+1,0))) --First of month after end month
N = ROW_NUMBER() OVER (ORDER BY t1.Object_ID)
FROM Master.sys.All_Columns t1
CROSS JOIN Master.sys.All_Columns t2
)
SELECT
NumberOfDays = DATEPART (dd, DATEADD(mm,DATEDIFF(mm,0,@DateStart)+t.N,0)-1 )
FROM MY_OTHER_CTE t
this query gives me ..
31-->january
29--feb
i wana substract 31 -5 to get
26-->jan
27-feb
am binding both query
any other way plz let me know ....
February 15, 2012 at 8:04 am
duplicate post. please direct all replies here. http://www.sqlservercentral.com/Forums/Topic1252488-392-1.aspx
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
February 15, 2012 at 8:23 am
sry how to remove duplicate posts ?
February 15, 2012 at 8:28 am
No problem. It happens sometimes. You can't remove a post. I just added a comment so others don't post here. Keeps your answers and discussion in one location.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply