在SQL Server中创建函数

时间:2015-11-30 05:25:04

标签: sql-server-2008

我想在SQL Server中创建一个函数

我创建了一个临时表但是我想在sqlserver中为下面的代码

创建函数
DECLARE @StartDate DATETIME
       ,@EndDate DATETIME;

SELECT 
    @StartDate ='20100101',
    @EndDate = GETDATE()
      --convert(varchar(8), GETDATE(),112); 

;With DT_TempTbl as
(
   SELECT 
       @StartDate AS YearMonth

   UNION ALL

   SELECT 
       DATEADD(MONTH, 1, YearMonth) 
   FROM 
       DT_TempTbl
   WHERE 
       YearMonth <= @EndDate
)
SELECT
    CONVERT(VARCHAR(6), YearMonth, 112) AS YearMonth1 
FROM 
    DT_TempTbl 
ORDER BY
    YearMonth1

请帮我在sqlserver中创建函数

0 个答案:

没有答案