Click here to Skip to main content
       

Database

 
GeneralRe: SQL Query To select result for monthly PinmemberJ4amieC11-Dec-12 0:11 
GeneralRe: SQL Query To select result for monthly PinmemberVishwaKL11-Dec-12 14:54 
AnswerRe: SQL Query To select result for monthly PinmemberMS SQL DEVELOPER10-Dec-12 23:35 
QuestionHow to get the closing balance to be the opening balance of the following month Pinmembervusamozi9-Dec-12 19:23 
AnswerRe: How to get the closing balance to be the opening balance of the following month PinmemberEddy Vluggen9-Dec-12 23:13 
AnswerRe: How to get the closing balance to be the opening balance of the following month Pinmember@AmitGajjar11-Dec-12 7:17 
QuestionSelect All Months and related data PinmemberVishwaKL6-Dec-12 22:21 
AnswerRe: Select All Months and related data PinmemberBlue_Boy7-Dec-12 1:18 
Here it is
create table #tempMonths (monthNr int)
insert into #tempMonths (monthNr) values (1) 
insert into #tempMonths (monthNr) values (2)
insert into #tempMonths (monthNr) values (3)
insert into #tempMonths (monthNr) values (4)
insert into #tempMonths (monthNr) values (5)
insert into #tempMonths (monthNr) values (6)
insert into #tempMonths (monthNr) values (7)
insert into #tempMonths (monthNr) values (8)
insert into #tempMonths (monthNr) values (9)
insert into #tempMonths (monthNr) values (10)
insert into #tempMonths (monthNr) values (11)
insert into #tempMonths (monthNr) values (12)
 
SELECT  isnull( YEAR(RequestedDate) ,YEAR(getdate()))  as Years,
isnull( Month(RequestedDate),temp.monthNr) as MonthInNumbers,temp.monthNr,
Count(Month(RequestedDate)) as MonthCount
 
FROM tblMYTABLE
right join #tempMonths temp on temp.monthNr =  Month(RequestedDate)
GROUP BY YEAR(RequestedDate),Month(RequestedDate),temp.monthNr
 
drop table #tempMonths

I Love T-SQL
"VB.NET is developed with C#.NET"
If my post helps you kindly save my time by voting my post.

GeneralRe: Select All Months and related data PinmemberMycroft Holmes8-Dec-12 20:57 
GeneralRe: Select All Months and related data PinmemberVishwaKL9-Dec-12 19:06 
GeneralRe: Select All Months and related data PinmemberMycroft Holmes9-Dec-12 19:15 
GeneralRe: Select All Months and related data PinmemberVishwaKL9-Dec-12 19:19 
GeneralRe: Select All Months and related data PinmemberVishwaKL9-Dec-12 18:37 
GeneralRe: Select All Months and related data PinmemberDeepak Kr110-Dec-12 19:27 
GeneralRe: Select All Months and related data PinmemberVishwaKL10-Dec-12 19:31 
GeneralRe: Select All Months and related data PinmemberDeepak Kr110-Dec-12 21:02 
GeneralRe: Select All Months and related data PinmemberVishwaKL10-Dec-12 21:46 
GeneralRe: Select All Months and related data PinmemberDeepak Kr110-Dec-12 22:25 
QuestionSSRS 2005 Pinmemberberba6-Dec-12 6:32 
AnswerRe: SSRS 2005 PinmemberDavid Mujica6-Dec-12 7:59 
AnswerRe: SSRS 2005 Pinmemberdjj556-Dec-12 9:30 
AnswerRe: SSRS 2005 PinmemberMycroft Holmes6-Dec-12 16:57 
GeneralRe: SSRS 2005 Pinmemberberba6-Dec-12 18:06 
GeneralRe: SSRS 2005 PinmemberMycroft Holmes6-Dec-12 21:43 
QuestionSQL Group By Question [modified] Pinmemberloyal ginger6-Dec-12 5:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Mobile
Web03 | 2.8.141015.1 | Last Updated 21 Oct 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid