Click here to Skip to main content
15,885,985 members
Home / Discussions / Database
   

Database

 
GeneralRe: SQL Query To select result for monthly Pin
J4amieC11-Dec-12 0:11
J4amieC11-Dec-12 0:11 
GeneralRe: SQL Query To select result for monthly Pin
VishwaKL11-Dec-12 14:54
VishwaKL11-Dec-12 14:54 
AnswerRe: SQL Query To select result for monthly Pin
MS SQL DEVELOPER10-Dec-12 23:35
MS SQL DEVELOPER10-Dec-12 23:35 
QuestionHow to get the closing balance to be the opening balance of the following month Pin
vusamozi9-Dec-12 19:23
vusamozi9-Dec-12 19:23 
AnswerRe: How to get the closing balance to be the opening balance of the following month Pin
Eddy Vluggen9-Dec-12 23:13
professionalEddy Vluggen9-Dec-12 23:13 
AnswerRe: How to get the closing balance to be the opening balance of the following month Pin
AmitGajjar11-Dec-12 7:17
professionalAmitGajjar11-Dec-12 7:17 
QuestionSelect All Months and related data Pin
VishwaKL6-Dec-12 22:21
VishwaKL6-Dec-12 22:21 
AnswerRe: Select All Months and related data Pin
Blue_Boy7-Dec-12 1:18
Blue_Boy7-Dec-12 1:18 
Here it is
SQL
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 Pin
Mycroft Holmes8-Dec-12 20:57
professionalMycroft Holmes8-Dec-12 20:57 
GeneralRe: Select All Months and related data Pin
VishwaKL9-Dec-12 19:06
VishwaKL9-Dec-12 19:06 
GeneralRe: Select All Months and related data Pin
Mycroft Holmes9-Dec-12 19:15
professionalMycroft Holmes9-Dec-12 19:15 
GeneralRe: Select All Months and related data Pin
VishwaKL9-Dec-12 19:19
VishwaKL9-Dec-12 19:19 
GeneralRe: Select All Months and related data Pin
VishwaKL9-Dec-12 18:37
VishwaKL9-Dec-12 18:37 
GeneralRe: Select All Months and related data Pin
Deepak Kr110-Dec-12 19:27
Deepak Kr110-Dec-12 19:27 
GeneralRe: Select All Months and related data Pin
VishwaKL10-Dec-12 19:31
VishwaKL10-Dec-12 19:31 
GeneralRe: Select All Months and related data Pin
Deepak Kr110-Dec-12 21:02
Deepak Kr110-Dec-12 21:02 
GeneralRe: Select All Months and related data Pin
VishwaKL10-Dec-12 21:46
VishwaKL10-Dec-12 21:46 
GeneralRe: Select All Months and related data Pin
Deepak Kr110-Dec-12 22:25
Deepak Kr110-Dec-12 22:25 
QuestionSSRS 2005 Pin
berba6-Dec-12 6:32
berba6-Dec-12 6:32 
AnswerRe: SSRS 2005 Pin
David Mujica6-Dec-12 7:59
David Mujica6-Dec-12 7:59 
AnswerRe: SSRS 2005 Pin
Corporal Agarn6-Dec-12 9:30
professionalCorporal Agarn6-Dec-12 9:30 
AnswerRe: SSRS 2005 Pin
Mycroft Holmes6-Dec-12 16:57
professionalMycroft Holmes6-Dec-12 16:57 
GeneralRe: SSRS 2005 Pin
berba6-Dec-12 18:06
berba6-Dec-12 18:06 
GeneralRe: SSRS 2005 Pin
Mycroft Holmes6-Dec-12 21:43
professionalMycroft Holmes6-Dec-12 21:43 
QuestionSQL Group By Question Pin
loyal ginger6-Dec-12 5:27
loyal ginger6-Dec-12 5:27 

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

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