Click here to Skip to main content
15,890,557 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
How to subtract two values in sql server which are in different columns in the same table

if I make subtract column A -B
and B-A, and put the reasult in new columns C,D

What I have tried:

A B C D
0 1 0 1
1 0 1 0
Posted
Updated 10-May-19 11:26am
Comments
[no name] 10-May-19 17:03pm    
Show your SQL and explain more exactly what you get and what you expect

1 solution

Try this:
SQL
SELECT A, B, A-B AS C, B-A AS D
FROM YourTable
 
Share this answer
 
Comments
Member 14363015 10-May-19 18:12pm    
thank you very much Maciej Los
but I have debit and credit so,
when I make subtract there be negative signal and I dont want it
for example
Debit credit Debit credit
0 46,059,428 0 46,059,428
3,222,243,539 0 3,222,243,539 0
5,748,834,383 5,962,428,984 0 213,585,601
4,834,505,607 4,762,018,830 81,486,777 0

like this any help
Maciej Los 11-May-19 10:00am    
Good advice!
[no name] 11-May-19 10:12am    
Thanks. Already 5ed your answer before long time, can not do it once again :)
Maciej Los 11-May-19 17:20pm    
Thank you, Bruno.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900