Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Math between columns

Author  Topic 

alexviseu
Starting Member

8 Posts

Posted - 2006-06-30 : 05:23:39
I need to create a new column where I subtract one column by another.
I've been looking fo that for a while now, can someone explain how to do this?

rockmoose
SQL Natt Alfen

3279 Posts

Posted - 2006-06-30 : 05:28:56
computed column:
alter table t add c as(a-b)

rockmoose
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-06-30 : 05:29:05
"I need to create a new column"
Alter table table_name add column_name datatype

"where I subtract one column by another."
can you explain more in detail ?



KH

Go to Top of Page

alexviseu
Starting Member

8 Posts

Posted - 2006-06-30 : 05:36:13
The thing is that I don't want to mess with tables, i want to do it in the query.

Does someone knows how to do that?
Go to Top of Page

alexviseu
Starting Member

8 Posts

Posted - 2006-06-30 : 05:38:37
khtan:

I've like:

SELECT *
FROM Table1 INNER JOIN Table2
ON Table1.stuff=table1.stuff

And I need to do something like:
SELECT *,(Table1.number-Table2.number) as Subtraction
FROM Table1 INNER JOIN Table2
ON Table1.stuff=table1.stuff
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-06-30 : 05:46:25
OK. I see what you want. You have already got it in your 2nd query.


KH

Go to Top of Page

alexviseu
Starting Member

8 Posts

Posted - 2006-06-30 : 06:04:29
rotfl, it was suposed to be pseudo code. Made up at the moment.

Thanks for the help. :)
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-06-30 : 07:00:49
>>I need to create a new column where I subtract one column by another.

No need to create New column. As is in your example use it in select query with proper column name

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -