Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Ramifications to Change Int to Number with Decimals

Status
Not open for further replies.

Coder7

Programmer
Oct 29, 2002
224
US
Good afternoon all.

My users want to change a value that's currently allowed as an integer to allow for 2 decimal places. Currently the attribute answer_value that's stored in the valid_answers table is data type
int(4). The data type for answer_value in the question_data table = varchar(500) which is why I have to cast it as integer in the query below.

What are the ramifications to the stored procedure below if I change the data type for answer_value in the valid_answers table to decimal (the values would have 2 decimal places)? I'm concerned about the accuracy of the calculation since I'm using float. Also, any other concerns that you see?

Thanks, as always, for your valuable input.
-----------------------------------------

CREATE PROCEDURE sp_ScoreValues_Get

@score FLOAT OUTPUT
,@tx_id INT

AS
BEGIN
Declare @s1 FLOAT
Declare @s2 FLOAT
Set NOCOUNT on
Set @tx_id = LTrim( RTrim( @tx_id) )

--Get the sum of the actual question answer values
SELECT @s1 = sum(cast(ques.answer_value AS INTEGER))
FROM QUESTION_DATA AS ques, VALID_ANSWERS AS ans
WHERE ques.score_value_ind = 'S'
and tx_id = @tx_id
and ques.code = ans.code
and ques.answer_value = ans.answer_value
and ans.valid_answer <> 'NA'

--Get the sum of the maximum question answer values possible
SELECT @s2 = sum(q.maxValues)
FROM
(
SELECT DISTINCT code, MAX(answer_value) AS maxValues
FROM VALID_ANSWERS
WHERE VALID_ANSWERS.code in
(
SELECT ques.code
FROM QUESTION_DATA AS ques, VALID_ANSWERS AS ans
WHERE ques.score_value_ind = 'S'
and tx_id = @tx_id
and ques.code = ans.code
and ques.answer_value = ans.answer_value
and ans.valid_answer <> 'NA')
GROUP BY code
)
AS q
SELECT @score = (@s1/@s2)

RETURN 0
END

GO
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top