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

Where Exists not working correctly

$
0
0

Hi,

Below is my insert proc query

	insert
	into	ODS.JJill.tODS_GLBalance
			(
				tUTL_JobLogging_Key,
			    PageNum, 
				FiscalYearId,
				FiscalMonthOfYearId,
	            Balance
			)
 select		DISTINCT		
							@tUTL_JobLogging_Key,
							vODS_GLBalance.PageNum,
							vODS_GLBalance.FiscalYearId,
							vODS_GLBalance.FiscalMonthOfYearId,
							GLAmount 
From ODS.Staging.vODS_GLBalance
    Left Outer Join Ods.JJill.tODS_GLBalance
											ON tODS_GLBalance.FiscalYearId				= vODS_GLBalance.FiscalYearId
											AND tODS_GLBalance.FiscalMonthOfYearId		= vODS_GLBalance.FiscalMonthOfYearId
											AND tODS_GLBalance.PageNum                    = vODS_GLBalance.PageNum
	  where  EXISTS
	  (
select *  From     ODS.Common.tODS_Date
where FiscalYearId = 2014
and   FiscalMonthOfYearId = 2
	  )
	  AND
      tODS_GLBalance.tUTL_JobLogging_Key Is NULL
       Order BY FiscalYearId ASC,
            FiscalMonthOfYearId ASC


And i am using where exists if the year = 2014 and month = 2 then only insert , but if i run this proc it inserts all the records for 2014.

Can someone please help me with how to change this one to get my task achieved?

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>