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

How to use where exists with a subquery

$
0
0

Hi,

Below is my query

select		DISTINCT		
							-1,
							vODS_GLBalance.PageNum,
							vODS_GLBalance.FiscalYearId,
							vODS_GLBalance.FiscalMonthOfYearId,
							GLAmount 
From ODS.Staging.vODS_GLBalance

											
	  where EXISTS
(
               select * 
			     From  ODS.Common.tODS_Date
                where dateid not in (-1,99991231) 
AND convert(date,convert(varchar,FiscalYearId)+'-'+convert(varchar,FiscalMonthOfYearID)+'-01') between dateadd(month,-2,getdate()) and dateadd(month,-1,getdate())
	  )

    
       Order BY FiscalYearId ASC,
            FiscalMonthOfYearId ASC

My subquery inside the where exists just brings the date for current month,so i want to limit my whole data only for current month,but if i run the whole query it returns me all the data i have in my staging table.

Any suggestions please?

Thanks


Viewing all articles
Browse latest Browse all 23857

Trending Articles



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