I am writing this post 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.
"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.
Fig 1: Divide Integer by Integer in SQL Server
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 OutputResultSELECT 100/CAST(11 AS FLOAT) AS OutputResultSELECT 100/CAST(11 AS DECIMAL(12,0)) AS OutputResultSELECT CAST(100 AS DECIMAL(12,0))/11 AS OutputResult
Fig 2: Get Decimal output result from Integer division in SQL Server
Such an amazing blog with new updates. I love to learn more about this topic. Waiting for more like this.
ReplyDeleteMicrosoft Dynamics crm Training in Chennai
Microsoft Dynamics Training in Chennai
Microsoft Dynamics crm Training institutes in Chennai
Salesforce Training in Chennai
AngularJS Training in Chennai
ccna course in Chennai
Microsoft Dynamics crm Training in Velachery
Microsoft Dynamics crm Training in T Nagar
Microsoft Dynamics crm Training in OMR
Great Article android based projects
DeleteJava Training in Chennai
Project Center in Chennai
Java Training in Chennai
projects for cse
The Angular Training covers a wide range of topics including Components, Angular Directives, Angular Services, Pipes, security fundamentals, Routing, and Angular programmability. The new Angular TRaining will lay the foundation you need to specialise in Single Page Application developer. Angular Training
this blog was really great, never seen a great blog like this before. i think im gonna share this to my friends.. Hex To Decimal
ReplyDelete
ReplyDeleteThrough this post, I know that your good knowledge in playing with all the pieces was very helpful. I notify that this is the first place where I find issues I've been searching for. You have a clever yet attractive way of writing on Msbi online training
Msbi online training Hyderabad
Msbi online training India
Msbi online course
Msbi course
Msbi training
Msbi certification training
Aivivu chuyên vé máy bay, tham khảo
ReplyDeletevé máy bay đi Mỹ bao nhiêu
vé máy bay từ mỹ về việt nam giá bao nhiêu
Vé máy bay từ Nhật Bản về Việt Nam
thông tin chuyến bay từ canada về việt nam
sql server dba online training
ReplyDeletesql server dba training
Fantastic article post.Really thank you! Awesome.
ReplyDeletecore java online training
java online training hyderabad