SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
ALTER FUNCTION f_NextTicketNo(@dt datetime)
RETURNS varchar(9)
AS
BEGIN
DECLARE @ym varchar(4)
SELECT @ym = CONVERT(varchar(4), @dt, 12)
RETURN(
SELECT @ym + RIGHT(100001 + ISNULL(RIGHT(MAX(Ticket_ID), 5), 0), 5)
FROM CLS_HelpDesk_Tickets_New WITH(XLOCK,PAGLOCK)
WHERE Ticket_ID like @ym+'%')
END
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO