Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
R.Prabu
Starting Member
33 Posts |
Posted - 2008-06-26 : 20:28:41
|
| My Query is SELECT Sum(FT.CallOutCharge) AS 'CallOutCharge', Convert(CHAR(3), CC.CompletedDate,109) As 'MonthName', month(CC.CompletedDate) As 'intMonth', Year(CC.CompletedDate) As 'Year' FROM HSSPMS_Tbl_Callcentre_Compliants AS CC INNER JOIN HSSPMS_Tbl_LandLordFulltimeEmployee AS FT ON FT.ContractorCode = CC.ContractorCode And CC.FaultCleared='1' WHERE FT.CreatedBy='LA2' AND FT.IsDelete='0' And Year(CC.CompletedDate)='2008' Group BY CC.CompletedDateMy Result Is------------CallOutCharge MonthName intMonth Year------------- --------- ----------- -----------300 Jun 6 2008500 Jun 6 2008But i need all the month of the year. i have all the Month in a table.but not workingI need a below resultCallOutCharge MonthName IntMonth Year-------------------- ------------- ----------- -----------0 January 1 20080 February 2 20080 March 3 20080 April 4 20080 May 5 2008800 June 6 20080 July 7 20080 August 8 20080 September 9 20080 October 10 20080 November 11 20080 December 12 2008any onr tell me how writeRegards,Prabu R |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2008-06-26 : 20:36:40
|
use LEFT JOINSELECT CallOutCharge = coalesce(c.CallOutCharge, 0), m.MonthName, m.MONTH, m.YEARFROM Tbl_Month m LEFT JOIN ( SELECT SUM(FT.CallOutCharge) AS 'CallOutCharge', CONVERT(CHAR(3), CC.CompletedDate,109) AS 'MonthName', MONTH(CC.CompletedDate) AS 'intMonth', YEAR(CC.CompletedDate) AS 'YEAR' FROM HSSPMS_Tbl_Callcentre_Compliants AS CC INNER JOIN HSSPMS_Tbl_LandLordFulltimeEmployee AS FT ON FT.ContractorCode = CC.ContractorCode AND CC.FaultCleared = '1' WHERE FT.CreatedBy = 'LA2' AND FT.IsDelete = '0' AND YEAR(CC.CompletedDate) = '2008' GROUP BY CC.CompletedDate ) c ON m.YEAR = c.YEAR AND m.MONTH = c.intMonth KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
R.Prabu
Starting Member
33 Posts |
Posted - 2008-06-26 : 20:44:39
|
| I have Executed this query but the Result isCallOutCharge MONTH------------- --------------------------------------------------0 January0 February0 March0 April0 May0 June0 July0 August0 September0 October0 November0 Decemberbut the June month have a valueRegards,Prabu R |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2008-06-26 : 20:48:44
|
pls post your month table's DDL, and sample data and also the exact query that you used KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
R.Prabu
Starting Member
33 Posts |
Posted - 2008-06-26 : 20:52:09
|
| My Exact Query isSELECT Sum(FT.CallOutCharge) AS 'CallOutCharge', Convert(CHAR(3), CC.CompletedDate,109) As 'MonthName', month(CC.CompletedDate) As 'intMonth', Year(CC.CompletedDate) As 'Year' FROM HSSPMS_Tbl_Callcentre_Compliants AS CC INNER JOIN HSSPMS_Tbl_LandLordFulltimeEmployee AS FT ON FT.ContractorCode = CC.ContractorCode And CC.FaultCleared='1' WHERE FT.CreatedBy=@OwnerId AND FT.IsDelete='0' And Year(CC.CompletedDate)=@Year Group BY CC.CompletedDateMy Month Table i have usedSET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOSET ANSI_PADDING ONGOCREATE TABLE [dbo].[HSSPMS_Tbl_Month]( [Id] [int] IDENTITY(1,1) NOT NULL, [Month] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, CONSTRAINT [PK_HSSPMS_Tbl_Month] PRIMARY KEY CLUSTERED ( [Id] ASC)WITH (PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]) ON [PRIMARY]GOSET ANSI_PADDING OFFI need a result very urgentRegards,Prabu R |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2008-06-26 : 20:58:13
|
How about the query where you left join from HSSPMS_Tbl_Month to your existing query ? KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
R.Prabu
Starting Member
33 Posts |
Posted - 2008-06-27 : 11:17:59
|
| Thank you its working fineRegards,Prabu R |
 |
|
|
|
|
|
|
|