我有两个表,我想加入以下列:
表:#IndexDecomposition;组分。
行:标识符;CUSIP;伊辛;世多乐。
这是一个更大的MERGE
语句的一部分,现在我认为交叉连接正在发生在INSERT
语句上:
MERGE indexdecomp.ConstituentWeighting targ
USING (#IndexConstituents src
INNER JOIN indexDecomp.Constituent c WITH (NOLOCK) on
((c.Identifier = src.Identifier) OR (c.Identifier IS NULL AND src.Identifier IS NULL))
AND ((c.CUSIP = src.CUSIP) OR (c.CUSIP IS NULL AND src.CUSIP IS NULL))
AND ((c.ISIN = src.ISIN) OR (c.ISIN IS NULL AND src.ISIN IS NULL))
AND ((c.SEDOL = src.SEDOL) OR (c.SEDOL IS NULL AND src.SEDOL IS NULL)))
ON ( targ.ConstituentId = c.Id
AND targ.AsOfDate = src.Date
AND ((targ.Weighting = src.Weighting) OR (targ.Weighting IS NULL AND src.Weighting IS NULL))
AND ((targ.TotalSharesHeld = src.TotalSharesHeld) OR (targ.TotalSharesHeld IS NULL AND src.TotalSharesHeld IS NULL))
AND ((targ.SharesOutstanding = src.SharesOutstanding) OR (targ.SharesOutstanding IS NULL AND src.SharesOutstanding IS NULL))
AND ((targ.NotionalValue = src.NotionalValue) OR (targ.NotionalValue IS NULL AND src.NotionalValue IS NULL))
AND ((targ.MarketValue = src.MarketValue) OR (targ.MarketValue IS NULL AND src.MarketValue IS NULL))
AND ((targ.MarketCap = src.MarketCap) OR (targ.MarketCap IS NULL AND src.MarketCap IS NULL))
AND ((targ.LastTrade = src.LastTrade) OR (targ.LastTrade IS NULL AND src.LastTrade IS NULL))
AND ((targ.Earnings = src.Earnings) OR (targ.Earnings IS NULL AND src.Earnings IS NULL))
AND ((targ.PeRatio = src.PeRatio) OR (targ.PeRatio IS NULL AND src.PeRatio IS NULL))
AND ((targ.Face = src.Face) OR (targ.Face IS NULL AND src.Face IS NULL)))
WHEN NOT MATCHED BY TARGET THEN
INSERT (
ConstituentID
,AsOfDate
,Weighting
,TotalSharesHeld
,SharesOutstanding
,NotionalValue
,MarketValue
,MarketCap
,LastTrade
,Earnings
,PeRatio
,Face
,ModifiedBy
,ModifiedDate
,CreatedBy
,CreatedDate
)
VALUES (
c.Id
,src.Date
,src.Weighting
,src.TotalSharesHeld
,src.SharesOutstanding
,src.NotionalValue
,src.MarketValue
,src.MarketCap
,src.LastTrade
,src.Earnings
,src.PeRatio
,src.Face
,'user'
,getdate()
,'user'
,getdate()
)
;