This is a horrible DB design. Having the same column store different values results in problems like this one. This actually looks to me like a problem you can fix with a pivot, or a CTE like this
select Total as GROSS, 0 as NET From tableName where Code='GROSS'
select 0 as GROSS, TOTAL as NET From tableName where Code='NET'
select gross, net, gross - net as difference
you can use sum in the final SQL if there's many values, but if there is, and there's no third column, your DB has even more issues.