Gurus,I wrote two queries for process of budget for next year.Those query is working fine. But i want to write it into one query. i ve tried for long time..can anyone help me to merge the query..?Select location , [3] AS [Mar-08] , [4] AS [Apr-08] , [5] AS [May-08] , [6] AS [Jun-08] , [7] AS [Jul-08] ,
AS [Aug-08] , [9] AS [Sep-08] , [10] AS [Oct-08] , [11] AS [Nov-08] , [12] AS [Dec-08] from ( SELECT l.location as Location,Month, a.Cost ,Year(getdate())+1 as Year FROM tblLFDMonth a INNER JOIN tblSpace b ON a.SpaceID = b.SpaceID INNER JOIN tlkpStatus c ON b.IsActive = c.StatusID INNER JOIN tlkpComponent d ON a.ComponentID = d.ComponentID INNER JOIN tlkpPmtStatus e ON a.PmtStatusID = e.PmtStatusID INNER JOIN tbllocation l on a.locationid = l.locationid where a.ComponentID =1 and c.PayRent = 1 and a.Year in (2008) and a.VariableExp = 0 And B.isactive =1 ) AS APIVOT ( max(Cost) for Month in ([3],[4],[5],[6],[7],
,[9],[10],[11],[12]) ) AS Bgroup by [3],[4],[5],[6],[7],
,[9],[10],[11],[12],locationOrder by 1Select location , [1] AS [Jan-09] , [2] AS [Feb-09] from ( SELECT l.location as Location,Month, a.Cost ,Year(getdate())+1 as Year FROM tblLFDMonth a INNER JOIN tblSpace b ON a.SpaceID = b.SpaceID INNER JOIN tlkpStatus c ON b.IsActive = c.StatusID INNER JOIN tlkpComponent d ON a.ComponentID = d.ComponentID INNER JOIN tlkpPmtStatus e ON a.PmtStatusID = e.PmtStatusID INNER JOIN tbllocation l on a.locationid = l.locationid where a.ComponentID =1 and c.PayRent = 1 and a.Year = 2009 and a.VariableExp = 0 And b.isactive = 1 ) AS APIVOT ( max(Cost) for Month in ([1],[2]) ) AS Bgroup by [1],[2],locationOrder by 1
ThanksKrishna