user1698232
user1698232

Reputation: 183

specify data type in sql query

I have a Runs table and this is my query

SELECT (pass*100)/total as pass from Runs where runId=1

I want the data type of the result returned to be decimal type.

How do I specify that ?

I did this after the query :

decimal.TryParse(reader["pass"].ToString(), out d1); d1 should be 83.4 but it is 83

Upvotes: 0

Views: 77

Answers (2)

Brave Soul
Brave Soul

Reputation: 3620

use cast to convert it to decimal and provide precision and scale accordingly

select cast((pass*100)/total as decimal(4,2)) from Runs where runId=1

Upvotes: 1

jarlh
jarlh

Reputation: 44766

Use CAST:

SELECT CAST((pass*100)/total as decimal) as pass from Runs where runId=1

(Provide DECIMAL precision and scale of your choice...)

Upvotes: 0

Related Questions