When I select the table
Select
[Premium Amount], [Policy Number],
[Transaction Type Code], Insured, *
from
DW.Table
where
[Policy Number] in ('1111111111', '2222222222')
these are the results.
Premium Amount Policy Number Transaction Type Code Insured
-12798.0000 1111111111 Cancellation ABC Group
27000.0000 1111111111 Renewal Business ABC Group
-8452.7700 2222222222 Cancellation DEF Group
10221.0000 2222222222 Renewal Business DEF Group
What I want to happen is to create two new columns, [Original Policy Premium] and [Transaction Premium].
[Original Policy Premium] is a column that contains when the Transaction Type Code = Renewal Business and it will result the corresponding Premium Amount = 27000.0000 for Policy Number 111111111. Same applies to Policy Number 22222222.
Make it look like this.
Original Policy Premium Transaction Premium Policy Number
27000.0000 -12798.0000 1111111111
10221.0000 -8452.7700 2222222222
Select
case
when [Transaction Type Code] = 'Renewal Business'
then [Premium Amount]
else ''
end as [Original Policy Premium],
case
when [Transaction Type Code] = 'Cancellation'
then [Premium Amount]
else ''
end as [Transaction Premium],
[Policy Number],
[Transaction Code]
from
DW.Table
where
[Policy Number] in ('111111111', '22222222')
But I get this error after running.
Msg 8114, Level 16, State 5, Line 1
Error converting data type varchar to numeric.
But when I replace END as '' with END AS NULL
Original Policy Premium Transaction Premium Policy Number
27000.0000 NULL 1111111111
NULL -12798.0000 1111111111
10221.0000 NULL 2222222222
NULL -8452.7700 2222222222
else null