I know the title is very vague but I didn't know how to explain this question better, if you have any suggestions please do tell me.
I have this table:
CRAccountID DBAccountID Value
And I want to have a row for each CRAccountID and DBAccountID for example:
CRAccountID DBAccountID Value
100 111 10
I want to get these records:
AccountID Value
100 10
111 -10
If you haven't noticed yet I also want to make the DBAccountID value in minus.
I tried it by selecting both of them and doing a Union but it takes way too much time when the table gets bigger (the table can contain more than 4 million records)
Here's my code:
select CRAccountID as AccountID, Value from MyTable
UNION
select DBAccountID as AccountID, -Value as Value from MyTable
Note: my code is much much bigger than this with almost 4 joins in each union therefore it becomes so slow.
I'm using Microsoft SQL.