Update temp table - tsql
I've got a temporary work table that i need to update the sector value
where the portfolio holds bonds and cash. Currently in the work table i'll
assign anything that is a bond to be "Bond" and anything to be cash to be
"Cash". I have an example table below:
PortfolioID IssueClassification Sector Weight
AAA 020 Bond 2.3
AAA 010 Cash 1.5
AAA 030 Equity 1.5
AAA 030 Equity 5.5
AAA 030 Equity 10.0
BBB 010 Cash 7.0
BBB 030 Equity 1.5
BBB 030 Equity 2.5
So what i would like to update the worktable with, is if like portfolio
AAA above holds both bonds and cash and i want to change its sector to
"Cash and Bonds". However if like portfolio BBB above it only holds cash
and no bonds then the sector should remain as "Cash". If a portfolio was
to hold bonds but no cash then the sector should still change to "Cash and
Bonds". I've looked at ways of developing this during the insert into my
#worktable but it would make the procedure far too inefficient.
So ultimately i want my above table to look like this:
PortfolioID IssueClassification Sector Weight
AAA 020 Cash and Bonds 2.3
AAA 010 Cash and Bonds 1.5
AAA 030 Equity 1.5
AAA 030 Equity 5.5
AAA 030 Equity 10.0
BBB 010 Cash 7.0
BBB 030 Equity 1.5
BBB 030 Equity 2.5
I'm unsure of the update script that could best achieve this. Any help?
No comments:
Post a Comment