convert mb to gb in sql server

Convert MB to GB in SQL Server

Hello everyone, I m going to share the query for convert MB to GM in sql server.

The Query as given below.

ALTER FUNCTION [DBO].[FUN_CONVERTMBTOGB]
(
            @USAGEINCLUSION BIGINT
)
RETURNS VARCHAR(50)
AS
BEGIN
            DECLARE @RETURN VARCHAR(50)
            DECLARE @ISRESULT VARCHAR(50)
            DECLARE @TGB INT
           
            IF(@USAGEINCLUSION >= 1024)
            BEGIN
                        SET @ISRESULT =(SELECT  CAST(@USAGEINCLUSION AS DECIMAL(18,2))/1024 AS INT)
                        SET @TGB = (SELECT VALUE FROM  [DBO].[SPLIT](@ISRESULT, '.') WHERE ID= 2)
                        IF @TGB > 0
                                     BEGIN                        
                                                SET @RETURN = CAST(FORMAT(CAST(@ISRESULT AS DECIMAL(18,2)),'N2') AS NVARCHAR(15)) + ' GB';
                                     END
                        ELSE
                                     BEGIN                        
                                                SET @RETURN =(SELECT VALUE FROM  [DBO].[SPLIT](@ISRESULT, '.') WHERE ID=1) + ' GB'
                                     END
            END
            ELSE
                        BEGIN
                                    SET @RETURN = CAST(@USAGEINCLUSION  AS NVARCHAR(15)) + ' MB';                     
                        END

            RETURN @RETURN


END




ANIL SINGH

Hey! I'm Anil Singh. I author this blog. I'm Active Blogger, Programmer. I love learning new technologies, programming, blogging and participating the forum discussions more...
My Blogs - http://www.code-sample.com and http://www.code-sample.xyz
My Books - Buy Books Online at Best Prices

You Might Also Like
Post a Comment
www.code-sample.com/. Powered by Blogger.