Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

As the title says. I even tried SELECT CONVERT(NUMERIC, 1/2) which also returned 0.

I am using SQL Server 2008.

share|improve this question
add comment

2 Answers

up vote 22 down vote accepted

They're integers.

Try:

select 1.0/2.0;

Or:

select CONVERT(NUMERIC,1)/CONVERT(NUMERIC,2);
share|improve this answer
add comment

First, you are executing the numbers as integers but second, you also have not defined the precision and scale of the numeric datatype.

Try this:

SELECT CONVERT(NUMERIC(5, 2), 1.0/2.0)

or even

SELECT CONVERT(NUMERIC(5, 2), 1/2.0)
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.