Sunday, 24 June 2018

Get Auto Increment No in Scalar Function in MS Sql

CREATE FUNCTION [dbo].[GETBookingOrderNo]()
RETURNS CHAR(9)
AS
BEGIN
DECLARE @lastval NVARCHAR(50)
SET @lastval = (SELECT MAX(BookingOrderNo) FROM BookingDetailMaster)
IF @lastval IS NULL SET @lastval = 'RO 000001'
--SET @lastval='RO 000009'
DECLARE @i INT
SET @i = RIGHT(@lastval,6) + 1
RETURN 'RO ' + RIGHT('0000' + CONVERT(VARCHAR(10),@i),6)
END
GO

SELECT [dbo].[GETBookingOrderNo]()

No comments:

Post a Comment

React Hooks - custom Hook

  v CustomHook Ø React allows us to create our own hook which is known as custom hook. Example – 1 localStorage Demo Step-1 Create ...