Case when 支持变量

--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

你可能感兴趣的:(Go)