SqlServer_小工具_存储空间单位自适应

CREATE FUNCTION FitSpace (@kbsize INT) RETURNS NVARCHAR(200)
AS
BEGIN
    DECLARE @rtn NVARCHAR(200);
    DECLARE @gb INT=1000000,
            @mb INT=1000,
            @kb INT=1;
    SELECT @rtn=CASE WHEN @kbsize>=@gb THEN CONCAT(CAST(ROUND(@kbsize*1.0/@gb,3) AS FLOAT),'GB')
                        WHEN @kbsize<@gb AND @kbsize>=@mb THEN CONCAT(CAST(ROUND(@kbsize*1.0/@mb,3) AS FLOAT),'MB')
                        WHEN @mb>=@kbsize THEN CONCAT(@kbsize,'KB')
                END;
    RETURN @rtn;
END

 

posted on 2017-10-16 02:28  Thancoo  阅读(341)  评论(0编辑  收藏  举报

导航