Hi All,
Below is my query which runs fine
Select Distinct Top 4 FiscalYearId, FiscalMonthOfYearId From ODS.Common.tODS_Date Inner Join UTL.Utility.tUTL_ProcessDate On tODS_Date.DateShort < tUTL_ProcessDate.ProcessDate And tUTL_ProcessDate.DatabaseName = 'ODS' Order By FiscalYearId Desc, FiscalMonthOfYearId Desc
Below is the generate output
FiscalYearId FiscalMonthOfYearId 2014 2 2014 1 2013 12 2013 11
But i want to use this query in one of my where clause condition as its being used in the where clause it can only return 1 row.So, i tried something like this
Select Distinct Top 4 FiscalMonthOfYearId From ODS.Common.tODS_Date Inner Join UTL.Utility.tUTL_ProcessDate On tODS_Date.DateShort < tUTL_ProcessDate.ProcessDate And tUTL_ProcessDate.DatabaseName = 'ODS' Order By FiscalMonthOfYearId Desc
And the result set of this one gives me the output like
FiscalMonthOfYearId 12 11 10 9
Which is not correct,( if you see the result set above).
Can someone please help me with any ides on this.