• Status: Solved
• Priority: Medium
• Security: Public
• Views: 241

# Probably easy SQL but urgent

Fairly simple here, probably.  Percent Goal, Units_data_warehouse, and OEM_Goal are all integers.  When I get my output, Percent goal is either 0 or 100.  I assume this is because of data types, but every attempt to fix it has resulted in arithmetic overflow or some other error.
``````UPDATE 	#output
SET Percent_Goal = ((Units_Data_Warehouse / OEM_Goal) * 100)
``````
0
zkeown
• 3
• 3
• 2
• +1
1 Solution

UPDATE  #output
SET Percent_Goal = (( cast(Units_Data_Warehouse as decimal(10,2) )  / OEM_Goal) * 100)
0

Commented:
Try this.

UPDATE #output
SET Percent_Goal = (Units_Data_Warehouse * 100) / OEM_Goal
0

Commented:
UPDATE  #output
SET Percent_Goal = ((CAST(Units_Data_Warehouse AS FLOAT)/ CAST(OEM_Goal AS FLOAT) * 100.00)
0

Author Commented:
Wow.  OK all solutions are close, however if the math evaluates to 4.6 I'm getting 4 and I need 5.
0

Commented:
Use CEIL function.

UPDATE #output SET Percent_Goal = CEIL((Units_Data_Warehouse * 100) / OEM_Goal);
0

UPDATE  #output
SET Percent_Goal =  ROUND ( (( cast(Units_Data_Warehouse as decimal(10,2) )  / OEM_Goal) * 100) , 2)
0

ooops

UPDATE  #output
SET Percent_Goal =  ROUND ( (( cast(Units_Data_Warehouse as decimal(10,2) )  / OEM_Goal) * 100) , 0)
0

Author Commented:
Neither is working... For instance one row has

Units_data_warehouse = 2
OEM_Goal = 43

2 / 43 = .0465...  * 100 = 4.65

But says 4.

0

Author Commented:
Ah ha!  Thanks aneeshattingal!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

## Featured Post

• 3
• 3
• 2
• +1
Tackle projects and never again get stuck behind a technical roadblock.