USE <Database_Name>
GO
IF OBJECT_ID(N'udf__GetDateByPart') IS NOT NULL
DROP FUNCTION [udf__GetDateByPart]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- *****************************************************************************
-- Name : udf__GetDateByPart
-- Author : Chandra Gunawan
-- Date : 30-Jul-13
-- Description : Returns the date data type from its part (year, month, day)
-- Parameters :
-- @pYear smallint Input year (e.g.: 2012)
-- @pMonth tinyint Input month (e.g.: 11)
-- @pDay tinyint Input day (e.g.: 3)
--
-- Usage Sample :
-- -------------------------------------------------
-- /* Return 11/3/2012 */
-- SELECT dbo.udf__GetDateByPart(2012, 11, 3)
-- -------------------------------------------------
--
-- Maintenance Log
-- =============================================================================
-- Date ID Description
-- -----------------------------------------------------------------------------
-- 25-Nov-08 chg Initial Revision
-- *****************************************************************************
CREATE FUNCTION udf__GetDateByPart
(
@pYear AS smallint,
@pMonth AS tinyint,
@pDay AS tinyint
)
RETURNS datetime
AS
BEGIN
RETURN CONVERT(varchar(2), @pMonth) + '/' + CONVERT(varchar(2), @pDay) + '/' +
CONVERT(varchar(4), @pYear)
END
GO
GRANT EXECUTE ON udf__GetDateByPart TO public
GO
No comments:
Post a Comment