次の列と結合したい 2 つのテーブルがあります。
テーブル: #IndexDecomposition; 構成要素。
行: 識別子。CUSIP; ISIN; セドル。
これはすべて、より大きな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()
)
;