15,746,652 members
1.00/5 (1 vote)
See more:
Write a sql function which will take number of balls as a input parameter and return number of overs Remaining depending on Number of Balls

For Eg : Input Parameter i.e Number of balls Remaining are 9

Output should be : 1.3 overs

What I have tried:

Write a sql function which will take number of balls as a input parameter
Posted
Updated 7-Mar-16 18:48pm
Patrice T 7-Mar-16 2:31am
[no name] 7-Mar-16 3:53am
didnt got it.can u explain me?
aarif moh shaikh 7-Mar-16 2:42am
No. of ball divide by 6.
[no name] 7-Mar-16 3:53am
Dat logic even i know, can u give me a function ?

## Solution 1

SQL
```Create function dbo.Solution (@var INT,@var1 INT)
returns NVARCHAR(10)
begin
DECLARE @final NVARCHAR(10)
DECLARE @B1 INT
DECLARE @B2 INT

select @B1= @var/@var1

SELECT @B2= @var-(@var1*@B1)
SET @final= CAST(@B1 AS nvarchar(10))  + '.'+ CAST(@B2 AS nvarchar(10))
return (@final )
end```

v2

## Solution 2

Try this

SQL
```Create function dbo.fn_GetOverFromBall (@input INT)
returns NVARCHAR(10)
begin
declare @finalresult nvarchar(10)
declare  @over int
declare @ballremaining int

select @over=@input/6 , @ballremaining=@input%6

set @finalresult=Convert(varchar(10),@over) + Convert(varchar(10),'.')  + Convert(varchar(10),@ballremaining)
return @finalresult
end```

and then call the function like this way
```select  dbo.fn_GetOverFromBall('14') as [OP]

--out put will be

OP
2.2```

Thanks