Case when 支援變數

xssh913913發表於2007-12-03

   --region [dbo].[uf_Ask_DoctorAdmin_ReturnSearchTimeChar]

SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Create By:        張升鵬
-- Create Date:      2007年月日
-- Create Description:  根據時間返回查詢時間的WHERE條件字串
-- Copyright:      www.91.cn
--
-- Modify By:
-- Modify Date:
-- Modify Description:
--
-- =============================================

ALTER FUNCTION [dbo].[uf_Ask_DoctorAdmin_ReturnSearchTimeChar]
(
 @AddTimeType INT -- 1:一天2:三天3:一週4:一月5:半年
)
RETURNS NVARCHAR(100)
AS
 BEGIN  
  DECLARE @TimeChar NVARCHAR(100)  

  SET @TimeChar =         
   CASE @AddTimeType
    WHEN 3 THEN 'DATEDIFF(dd, AddTime, GETDATE()) <= 7'
    WHEN 1 THEN 'DATEDIFF(dd, AddTime, GETDATE()) = 0'
    WHEN 2 THEN 'DATEDIFF(dd, AddTime, GETDATE()) <= 3'
    WHEN 4 THEN 'DATEDIFF(dd, AddTime, GETDATE()) <= 30'
    WHEN 5 THEN 'DATEDIFF(dd, AddTime, GETDATE()) <= 180'
    ELSE 'DATEDIFF(dd, AddTime, GETDATE()) <= 7'      
   END
  RETURN @TimeChar
 END
GO

--endregion

相關文章