SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Calculated Field ( division)
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

andrewcw
Posting Yak Master

USA
129 Posts

Posted - 01/20/2006 :  13:31:54  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

Sri Lanka
1378 Posts

Posted - 01/20/2006 :  13:43:59  Show Profile  Reply with Quote
/ - 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

USA
129 Posts

Posted - 01/20/2006 :  13:44:00  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

Sri Lanka
1378 Posts

Posted - 01/20/2006 :  13:45:32  Show Profile  Reply with Quote
heh hey 1 second
Go to Top of Page

andrewcw
Posting Yak Master

USA
129 Posts

Posted - 01/20/2006 :  13:48:39  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

Sri Lanka
1378 Posts

Posted - 01/20/2006 :  14:19:47  Show Profile  Reply with Quote
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

USA
129 Posts

Posted - 01/20/2006 :  16:29:25  Show Profile  Reply with Quote
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

USA
129 Posts

Posted - 01/20/2006 :  17:08:48  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000