ALTER FUNCTION [udf_DateTimeFromDataDtID]
(
@DATA_DT_ID int -- In form YYYYMMDD
)
RETURNS datetime
WITH SCHEMABINDING
AS
BEGIN
RETURN CONVERT(datetime, CONVERT(varchar, @DATA_DT_ID))
END
或者这个(因为字符串/日期文字 - 是的,我也试过'1900-01-01'):
ALTER FUNCTION udf_CappedDate
(
@DateTimeIn datetime
)
RETURNS datetime
WITH SCHEMABINDING
AS
BEGIN
IF @DateTimeIn < '1/1/1900'
RETURN '1/1/1900'
ELSE IF @DateTimeIn > '1/1/2100'
RETURN '1/1/2100'
RETURN @DateTimeIn
END