Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
I have two select statement and want to combine into one.The first one return like this;1st 2nd 3rd 4th34 12 99 85The second one return like this;Total230I want the final looks like this;1st 2nd 3rd 4th total34 12 99 85 230My sql statement like this;DECLARE @fisyear1 INT, @fisyear2 INT, @fisyear3 INTSET @fisyear1 = 2012SET @fisyear2 = @fisyear1*10000 + 701SET @fisyear3 = @fisyear1*10000 + 10930SELECT *FROM (SELECT SUM(S.[Shape_STLength__]) AS "TOTAL" , CASE WHEN MONTH(I.[ACTFINISHDATE]) BETWEEN 7 AND 9 THEN '1st' WHEN MONTH(I.[ACTFINISHDATE]) BETWEEN 10 AND 12 THEN '2nd' WHEN MONTH(I.[ACTFINISHDATE]) BETWEEN 1 AND 3 THEN '3rd' WHEN MONTH(I.[ACTFINISHDATE]) BETWEEN 4 AND 6 THEN '4th' END AS QUARTERFROM [CLGT].[azteca].[INSPECTION] IINNER JOIN [LGDM].[GIS].[SSGRAVITYMAIN] SON I.ENTITYUID = S.FACILITYIDWHERE (I.INSPTEMPLATENAME = 'Line Cleaned') AND (I.STATUS = 'CLOSED') and I.[ACTFINISHDATE] >= CONVERT(datetime, convert(char(8),@fisyear2)) GROUP BY MONTH(I.[ACTFINISHDATE]), DATEPART("YY", I.[ACTFINISHDATE])) PPIVOT (SUM(TOTAL) FOR QUARTER IN([1st],[2nd],[3rd],[4th])) AS quarterdaySELECT SUM(S.[Shape_STLength__]) AS "TOTAL"FROM [CLGT].[azteca].[INSPECTION] IINNER JOIN [LGDM].[GIS].[SSGRAVITYMAIN] SON I.ENTITYUID = S.FACILITYIDWHERE (I.INSPTEMPLATENAME = 'Line Cleaned') AND (I.STATUS = 'CLOSED') and I.[ACTFINISHDATE] >= CONVERT(datetime, convert(char(8),@fisyear2)) and I.[ACTFINISHDATE] <= CONVERT(datetime, convert(char(8),@fisyear3))