Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (6.1k points)

A column height is in int type in my SQL Server table. I need to do a division and produce the result as a decimal in my query.

Select (height/10) as HeightDecimal

How would I cast and so that the HeightDecimal is no longer integer? 

1 Answer

0 votes
by (12.7k points)
edited by

Try the following code:

SELECT height/10.0 AS HeightDecimal FROM dbo.whatever;

If you require a specific precision scale, then say so: 

SELECT CONVERT(DECIMAL(16,4), height/10.0) AS HeightDecimal
  FROM dbo.whatever;

Want to learn more concepts related to SQL? Join this SQL Course by Intellipaat.

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Browse Categories

...