Sample Table Data
Declare @t table (PolicyNumber varchar(10),Val decimal(18,2),Fund varchar(5),Tenure varchar(10))
INSERT INTO @t(PolicyNumber,Val,Fund,Tenure)VALUES
('ASWPP',10.2,'T001','Secure'),
('ASWPP',5.0,'T002','Secure'),
('ASWPP',5.0,'T003','Secure'),
('XPPW',15.2,'T001','Growth'),
('XPPW',10.2,'T002','Growth'),
('XPPW',10.2,'T003','Growth'),
('XXXX',20.2,'T001','Secure'),
('XXXX',10.2,'T002','Secure'),
('XXXX',10.2,'T003','Secure')
How to do the Subtraction from same table basing on Policy number.
I need to subtract the Fund = 002 from the other funds (T001,T003)
I need to get the output like below :
PolicyNumber Val Fund Tenure
ASWPP 5.2 T001 Secure
ASWPP 0.0 T003 Secure
XPPW 5.2 T001 Growth
XPPW 0.2 T003 Growth
XXXX 10.2 T001 Secure
XXXX 0.0 T003 Secure
Suggest me the best way