Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Power function in T SQL

The following returns .81 as expected:

select .9*.9;  

But this does not. Its return value is .8:

select power(.9, 2)

To have it return .81, I have to cast the input:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

select power(cast(.9 as float), 2)

Why is a cast needed here? What am I missing?

>Solution :

The power function return type is dictated by the data type of the first parameter. Here, you’re giving it a decimal(1,1). As noted in the documentation, it’s returning a decimal(38,1).

You’ll get the result you want by either casting, as you’ve done, or by feeding the function differently.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading