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
 PLEASE HELP - Divide Statement

Author  Topic 

N8thanAshley
Starting Member

1 Post

Posted - 2008-05-07 : 14:30:36
I would like to divide the value of column_2 by the value of column_3 and have the result returned in a new_column.....

"SELECT column_1, column_2, column_3, (dbo.column_2 "DIVIDED BY" dbo.column_3) AS new_column

FROM dbo"

Do I have to create a 'temp table' to do this?

If you cannot tell, I am VERY new to this and would appreciate any help!!!

Thank you in advance! Nathan

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-05-07 : 14:34:39
SELECT column_1, column_2, column_3, column_2/column_3 AS new_column
FROM Table1

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Database maintenance routines:
http://weblogs.sqlteam.com/tarad/archive/2004/07/02/1705.aspx
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-05-07 : 15:01:01
If you are unsure whether column_3 may contain zero value you need to do this to aviod divide by zero error
SELECT column_1, column_2, column_3, ISNULL((column_2/NULLIF(column_3,0)),0) AS new_column
FROM Table1
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-05-08 : 04:06:27
Also if columns are of INT type and you want values with precision,

SELECT column_1, column_2, column_3, 1.0*column_2/column_3 AS new_column
FROM Table1

Madhivanan

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

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-05-08 : 04:17:09
Darn.
I was going to write

Read my lips; I-N-T-E-G-E-R D-I-V-I-S-I-O-N



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page
   

- Advertisement -