CREATE FUNCTION [dbo].[f_NextBH]() RETURNS nvarchar(50) AS BEGIN RETURN(SELECT 'LS'+replace(CONVERT(varchar(10), GETDATE(), 112),'-','')+RIGHT(1000000000001+ISNULL(RIGHT(MAX(SettleNo),12),0),12) FROM Shop WITH(XLOCK,PAGLOCK)) END