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
 how to sumtract columns

Author  Topic 

vnsbabu
Starting Member

1 Post

Posted - 2007-06-25 : 01:08:01
how to subtract values from column to another

ch..

pbguy
Constraint Violating Yak Guru

319 Posts

Posted - 2007-06-25 : 01:12:59
Do u mean creating a computed column by subtracting a column from another column?
give some sample data...

--------------------------------------------------
S.Ahamed
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-06-25 : 03:32:52
quote:
Originally posted by vnsbabu

how to subtract values from column to another

ch..


Select col1, col2, col1-col2 as new_col from table

You need to Learn SQL

Madhivanan

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

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-06-25 : 03:34:26
Also you need to handle NULL

Madhivanan

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

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-06-25 : 03:59:21
Learn SQL:

http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp

(© Madhi)

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

noorahmed.shaik
Starting Member

11 Posts

Posted - 2007-06-25 : 11:12:08
quote:
Originally posted by vnsbabu

how to subtract values from column to another

ch..




MEANS TO SAY COMPUTED COLUMNS

Noor Ahmed
Keysoft solution
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-06-25 : 11:18:28
A computed column is computed from an expression that can use other columns in the same table. The expression can be a noncomputed column name, constant, function, variable, and any combination of these connected by one or more operators. The expression cannot be a subquery.

For example, in the AdventureWorks sample database, the TotalDue column of the Sales.SalesOrderHeader table has the definition: TotalDue AS Subtotal + TaxAmt + Freight.

Something like

ALTER TABLE Table1 ADD ColNew AS (Col1 + Col2 - Col3)



Peter Larsson
Helsingborg, Sweden
Go to Top of Page
   

- Advertisement -