sqlserver 自定义函数使用Getdate()的变通方法
1,先建一个视图
CREATE view v_getdate
as
select convert(varchar(4), getdate(),20) as dt
2,建立函数
CREATE FUNCTION f_NextBH()
RETURNS varchar(50)
AS
BEGIN
declare @GetDate varchar(4)
select @GetDate = dt from v_getdate
RETURN(SELECT 'TYKJ/QC_' + CONVERT(VARCHAR(4),@GetDate) + '_' + RIGHT(10001 + ISNULL(RIGHT(MAX(文件编号), 4), 0), 4) FROM tb_YiShengJi WITH (XLOCK, PAGLOCK)WHERE (CONVERT(VARCHAR(4), 录入日期, 20) = CONVERT(VARCHAR(4),@GetDate)))
END