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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Calculated Field ( division)

Author  Topic 

andrewcw
Posting Yak Master

133 Posts

Posted - 2006-01-20 : 13:31:54
SELECT Mean_F, StdDev_F, NumGadgets, LastUpDate, Proc_FKey, NumFails, NumFails / NumGadgets AS MeanFailure
FROM dbo.StatProcMain
WHERE (Proc_FKey = 7)

If I use + or * I get the calculated field, but / and I get 0.
where numGadgets = 50 and NumFails = 10

How do I represent division ? Thanks

andrewcw

Srinika
Master Smack Fu Yak Hacker

1378 Posts

Posted - 2006-01-20 : 13:43:59
/ - does integer division if both denominator & numerator r integers
thus 3/7 = 0

convert either or both to float or decimal
Go to Top of Page

andrewcw
Posting Yak Master

133 Posts

Posted - 2006-01-20 : 13:44:00
OH I know part of the problem, the calc field wants to be an integer, what do I do to specify a real ( when I reversed it to get 50/10 I got an answer ... So please help with field specification

andrewcw
Go to Top of Page

Srinika
Master Smack Fu Yak Hacker

1378 Posts

Posted - 2006-01-20 : 13:45:32
heh hey 1 second
Go to Top of Page

andrewcw
Posting Yak Master

133 Posts

Posted - 2006-01-20 : 13:48:39
OK ?? I how do I do that ??? : ( not like this:)

SELECT Mean_F, StdDev_F, NumPlanes, LastUpDate, Proc_FKey, NumFails, type real (NumPlanes) / type real ( NumFails) AS MeanFailure
FROM dbo.StatProcMain
WHERE (Proc_FKey = 5)

andrewcw
Go to Top of Page

Srinika
Master Smack Fu Yak Hacker

1378 Posts

Posted - 2006-01-20 : 14:19:47
Check the convert function in Books OnLine of Query Analyzer

check this

declare @a int
Set @a = 3
Print @a/7

and then check
Print convert(decimal(4,2), @a)/7

Use the same in ur fields
Print 3/7.0

Go to Top of Page

andrewcw
Posting Yak Master

133 Posts

Posted - 2006-01-20 : 16:29:25
Thanks I will have to see how I could use that within an ad hoc query instead of a stored procedure

andrewcw
Go to Top of Page

andrewcw
Posting Yak Master

133 Posts

Posted - 2006-01-20 : 17:08:48
SELECT Mean_F, StdDev_F, NumGadgets, LastUpDate, Proc_FKey, NumFails, CONVERT(real, NumFails) / CONVERT(real, NumGadgets) AS MeanFailure
FROM dbo.StatProcMain
WHERE (Proc_FKey = 5)

IT NOW WORKS FINE THANKS TO SRINIKA !

andrewcw
Go to Top of Page
   

- Advertisement -