0

I must be a total idiot or something. I'm using Microsoft SQL Server 2008. I can't do simple division. SELECT 200/600 returns a big fat goose egg (0.00). Yet if I do 600/200 it returns 3. The only thing I can think of is some server setting. I'm feeling pretty darn stupid here. Can somebody please help?

Shown on my server

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Gregbert
  • 121
  • 1
  • 11

1 Answers1

5

The numbers you are using are being interpreted as integers, hence values you might not normally expect.

Try this...

select 200.0/600.0

and you'll see that SQL Server treats the numbers as floats and therefore gives you the result you want.

Alternatively you could try

select cast (200 as float) / cast (600 as float)

And you'd get the same result - all I've done here is to explicitly cast the values as floats.

Mat Richardson
  • 3,576
  • 4
  • 31
  • 56