Wednesday, June 8, 2016

Over To Ball Calculator in SQL Server

//Over To Ball Calculator
//use to cricket
Create PROCEDURE [dbo].[Sp_OverToBall] @over VARCHAR(50)
AS
  BEGIN
      SET nocount ON;

      DECLARE @@Over INT
      DECLARE @@Bal NUMERIC(18, 2)
      DECLARE @@SubBal INT
      DECLARE @@SubOver INT

      IF( Charindex('.', @over) != 0 )
        BEGIN
            SET @@Bal= Substring(@over, Charindex('.', @over) + 1, Len(@over))
            SET @@Over = Substring(@over, 0, Charindex('.', @over))
        END
      ELSE
        BEGIN
            SET @@Bal= 0
            SET @@Over = @over
        END

      IF( @@Bal > 6 )
        BEGIN
            SET @@SubBal = @@Bal % 6
            SET @@SubOver = ( @@Bal - @@SubBal ) / 6
        END
      ELSE
        BEGIN
            SET @@SubBal = @@Bal
        END

      SELECT Isnull(@@Over, 0) + Isnull(@@SubOver, 0) [Over],
             Isnull(@@SubBal, 0) Ball,
             Isnull(@@SubBal, 0) + ((Isnull(@@Over,0) + Isnull(@@SubOver, 0))* 6 )TotalBall
  END



-----O/P:=
Over  Ball  TotalBall
20         0       120

No comments: