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.
Author |
Topic |
Dasman
Yak Posting Veteran
79 Posts |
Posted - 2011-06-24 : 13:08:26
|
Dear All,I have this function:set ANSI_NULLS ONset QUOTED_IDENTIFIER ONgoALTER FUNCTION [dbo].[Function3] (@PatientID int, @RecordingID int)RETURNS TABLE ASRETURN (SELECT(SELECT * FROM dbo.Function1 (@PID, @RID)) / (SELECT * FROM dbo.Function2 (@PID, @RID)) AS Function3)Now when this function along with Functions 1 and 2 are ran in a stored procedure for a certain PID and RID I get the following results:Function1 = 102Function2 = 131Function3 = 0Should I CAST as something? Why doesn't it output a number?Thanks,Dasman==========================Pain is Weakness Leaving the Body. |
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2011-06-24 : 13:10:17
|
RETURN (SELECT 1.0 * (SELECT * FROM dbo.Function1 (@PID, @RID)) / (SELECT * FROM dbo.Function2 (@PID, @RID)) AS Function3)102/131 truncated to an integer = 0==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
|
|
Dasman
Yak Posting Veteran
79 Posts |
Posted - 2011-06-24 : 13:16:14
|
AWESOME! that was soo quick! Thank you Nigel and it now yields a value of 0.778625954198which is mathematically correct!One followup - How can i chose for it round off after two decimal places? To make the answer: 0.78? or 0.779?Dasman==========================Pain is Weakness Leaving the Body. |
|
|
Bustaz Kool
Master Smack Fu Yak Hacker
1834 Posts |
Posted - 2011-06-29 : 17:48:34
|
Lookup ROUND function in Books Online.=======================================I have never met a man so ignorant that I couldn't learn something from him. -Galileo Galilei, physicist and astronomer (1564-1642) |
|
|
|
|
|