复制代码 代码如下:
SELECT [StartDate] FROM [dbo].[udf_Week](2012,2012) WHERE [Week] = 1
复制代码 代码如下:
udf_StartDateOfFirstWeek
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION udf_StartDateOfFirstWeek
(
@Year INT
)
RETURNS DATE
AS
BEGIN
DECLARE @StartDate DATE = CAST((CAST(@Year AS VARCHAR(4)) + '-01-01') AS DATE)
RETURN
CASE WHEN (DATEPART(DW,@StartDate) > 4)
THEN DATEADD(DAY,(8 - DATEPART(DW,@StartDate)) ,@StartDate)
ELSE DATEADD(DAY,(-(DATEPART(DW,@StartDate)-1)),@StartDate)
END
END
GO
新闻热点
疑难解答