Wednesday, March 7, 2012

quick question

Write a sql that divides 8 by 3 cast 3 as a decimal rounded to 2 places \
???????????
HOW do i do this im confused and new to this!!!At least one of your values must be non-integer, and you must cast your final results to two decimal places of accuracy. Otherwise, SQL Server works with integers by default becuase they can be processed more quickly, and it will thus round off your answer.

All these work:
select cast(8/cast(3 as decimal(10,2)) as decimal(10,2))
select cast(cast(8 as decimal(10,2))/cast(3 as decimal(10,2)) as decimal(10,2))
select cast(8/3.0 as decimal(10,2))

...but this does not:
select cast(8/3 as decimal(10,2))

blindman|||Thanks a lot!!!|||bm: SQL does not choose integers because they are easy to work with...That's funny even to think that way :)

Read BOL on datatype conversion rules!!!|||rdj, you need to give it a rest already.|||Pigeon: I would, but bm never gives up :) Plus, his last answer was really funny, so I couldn't resist :D|||You're welcom, dirtysouthchick!

Glad I could be of help to you.

blindman|||go to bed, bm, tomorrow is just another day :)|||Just curious rdjabarov, why the beef with Blindie?|||Nevermind, I just caught up reading the other posts :)|||I don't have a beef, I just see that sometimes all of us (or some of us) prefer a p***ing contest over the opportunity to hear each other out. And I am as guilty in doing this as the next guy. I just don't want to be a part of a place like this, so I hope that we all re-think the reason why we chose to be here in the first place.

Other than that, - life is good :)

No comments:

Post a Comment