Integer division to float division in SQL server

Problem statement : I have a use case where i need to see how much percentage each day with respect to days in a week.

Solution in Mathematics :  since there are 7 days in a week , so the solution will be (1/7) * 100 = 14.28

Solution in SQL server:

If we apply the same logic in SQL server the result will be 0 because with will be a integer vision.

To convert this into float division we need to us 'cast (<integer> as float)' in the denominator. Please refer to the screen shot below.







 

Comments

Popular posts from this blog

SCD 2 Using Merge statement in SQL server

Flatten / Parsing XML using Azure ADF (Azure data factory)