sql 获取24小时列表

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/waterstar50/article/details/77992221
 /*分时临时表*/
CREATE TABLE #tmpTime ( TimeValue VARCHAR(10) )
/*每小时列表*/
/*8:00-24:00*/
INSERT  INTO #tmpTime
        ( TimeValue 
                
        )
        SELECT  RIGHT('00' + CAST(number AS VARCHAR(5)), 2)
                + ':00'
        FROM    master.dbo.spt_values
        WHERE   type = 'P'
                AND number BETWEEN 8 AND 24
/*1:00-7:00*/                
INSERT  INTO #tmpTime
        ( TimeValue 
                
        )
        SELECT  RIGHT('00' + CAST(number AS VARCHAR(5)), 2)
                + ':00'
        FROM    master.dbo.spt_values
        WHERE   type = 'P'
                AND number BETWEEN 1 AND 7
                
/*删除临时表*/                
DROP TABLE #tmpTime

展开阅读全文

没有更多推荐了,返回首页