Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

How to get accurate values for select statement using single column

$
0
0

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.


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>