时间差函数使用

来源:互联网 发布:网络风油精是什么意思 编辑:程序博客网 时间:2024/06/14 06:00
IF OBJECT_ID('[dbo].[get_service_status]') IS NOT NULL   DROP FUNCTION [dbo].[get_service_status]GOCREATE FUNCTION [dbo].[get_service_status](    @arrear_time    datetime,    @reminder_time  int,       (单位:天)    @buffer_time    int            (单位:天))RETURNS nvarchar(10)ASBEGIN    DECLARE @service_status nvarchar(10)    SET @service_status = '状态1'        -- 当前时间    DECLARE @current_time datetime    --SET @current_time = getdate()  -- sqlserver2000中不能这样调用    SELECT @current_time = Today FROM [dbo].[view_get_date]    -- 时间差    DECLARE @nDiffDay int    SELECT @nDiffDay = datediff(dd, @current_time, @arrear_time)        IF (@nDiffDay > @reminder_time)    BEGIN       SET @service_status = '状态1'    END    ELSE IF (@nDiffDay <= @reminder_time AND @nDiffDay >= 0)    BEGIN       SET @service_status = '状态2'    END    ELSE IF (@nDiffDay < 0 AND @nDiffDay >= -@buffer_time)    BEGIN       SET @service_status = '状态3'    END    ELSE     BEGIN       SET @service_status = '状态4'    END        RETURN @service_statusENDGO


原创粉丝点击