Playback starts YouTube’s embedded player (privacy-enhanced mode).
Get Decimal/Float output from Integer Division in SQL Server - SQL Server Tutorial
ChannelTechBrothersITDescription from the creator
In this video we will learn how to get decimal/float output from Integer division in SQL Server.
I am creating this video to answer once of the question that I posted while back for TSQL Interview Question list
"If I run Select 100/11 what output will I get?"
When you divide Integer by an Integer in SQL Server, SQL Server returns Integer output.
As we can see from our above example, SQL Server output is Integer for Integers division. If we want to get float or Decimal output, Either our denominator or Numerator should be float or decimal type.
If we have both denominator or numerator as Integers, we can use convert or cast functions to convert one of them to float/decimal so we can get our results as float/decimal.
There are multiple techniques you can use to convert/cast to integer to float/decimal, here are some examples
SELECT CAST(100 AS FLOAT) /11 AS OutputResult
SELECT 100/CAST(11 AS FLOAT) AS OutputResult
SELECT 100/CAST(11 AS DECIMAL(12,0)) AS OutputResult
SELECT CAST(100 AS DECIMAL(12,0))/11 AS OutputResult
Blog post link with scripts used in the video
sqlage.blogspot.com/2015/02/how-to-get-decimail…
I am creating this video to answer once of the question that I posted while back for TSQL Interview Question list
"If I run Select 100/11 what output will I get?"
When you divide Integer by an Integer in SQL Server, SQL Server returns Integer output.
As we can see from our above example, SQL Server output is Integer for Integers division. If we want to get float or Decimal output, Either our denominator or Numerator should be float or decimal type.
If we have both denominator or numerator as Integers, we can use convert or cast functions to convert one of them to float/decimal so we can get our results as float/decimal.
There are multiple techniques you can use to convert/cast to integer to float/decimal, here are some examples
SELECT CAST(100 AS FLOAT) /11 AS OutputResult
SELECT 100/CAST(11 AS FLOAT) AS OutputResult
SELECT 100/CAST(11 AS DECIMAL(12,0)) AS OutputResult
SELECT CAST(100 AS DECIMAL(12,0))/11 AS OutputResult
Blog post link with scripts used in the video
sqlage.blogspot.com/2015/02/how-to-get-decimail…
About this tutorial
TechBrothersIT published this 2:47 video tutorial on November 11, 2015. It has been watched 23,915 times on YouTube.
- Channel
- TechBrothersIT
- Category
- Science & Technology
- Duration
- 2:47
- Published
- November 11, 2015
- Views
- 23,915
- Likes
- 69
Tags
Share
This tutorial in other languages
- FRObtenez décimal / sortie flottante de division entière dans SQL Server - Tutorial SQL Server
- ESObtener una salida Decimal / flotador de la división entera en SQL Server - Tutorial de SQL Server
- PTObter saída Decimal / Float da divisão inteira no SQL Server - SQL Server Tutorial
- ITOttenere uscita Decimale / Float dalla divisione intera in SQL Server - SQL Server Tutorial
- DEGet Dezimal / Float Ausgabe von Integer-Division in SQL Server - SQL Server Tutorial
- NLGet Decimal / Float output van Integer Division in SQL Server - SQL Server Tutorial
- RUПолучить выход Десятичного / Float от целочисленного деления в SQL Server - SQL Server Учебник
- PLUzyskaj wyjście dziesiętne / Float od Integer Division w SQL Server - SQL Server Tutorial
- JASQL Serverのチュートリアル - SQL Serverでの整数除算から小数点/浮動小数点出力を取得します。
- ARالحصول على إخراج عشري / تعويم من قسمة عدد صحيح في SQL Server - SQL خادم تعليمي
- HIएसक्यूएल सर्वर ट्यूटोरियल - एसक्यूएल सर्वर में पूर्णांक डिवीजन से दशमलव / फ्लोट उत्पादन प्राप्त करें
- IDMendapatkan output Decimal / mengambang dari Divisi Integer di SQL Server - SQL Server Tutorial