Creating date in SQL Server 2008

前端 未结 3 1944
天命终不由人
天命终不由人 2021-02-07 01:23

Is there something similar to DATEFROMPARTS(year, month, day) in SQL Server 2008? I want to create a date using the current year and month, but my own day of the mo

3条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-07 01:51

    CREATE FUNCTION  DATEFROMPARTS
    (
        @year int,
        @month int,
        @day int
    )
    RETURNS datetime
    AS
    BEGIN
    
         declare @d datetime
    
         select @d =    CAST(CONVERT(VARCHAR, @year) + '-' + CONVERT(VARCHAR, @month) + '-' + CONVERT(VARCHAR, @day) AS DATETIME)
        RETURN  @d 
    
    END
    GO
    

提交回复
热议问题