CREATE TABLE [dbo].[Mst_Emp](
[Emp_Id] [VARCHAR](10) NOT NULL PRIMARY KEY,
[CountryId] [int] NULL,
[StateId] [int] NULL,
[CityId] [int] NULL,
[Fst_Name] [varchar](50) NULL,
[Lst_Name] [varchar](50) NULL,
[Email] [varchar](50) NULL,
[Gender] [varchar](50) NULL,
[D_O_B] [datetime] NULL,
[Password] [varchar](50) NULL,
[CPassword] [varchar](50) NULL,
[Image] [varchar](max) NULL)
CREATE PROCEDURE USP_Mst_Emp
(
@ACTION VARCHAR(50)
)
AS BEGIN --BEGIN OF PROC
IF(@ACTION='GET_MAX_ID')
BEGIN --BEGIN OF IF
DECLARE @EMP_MAX VARCHAR(9),@MAX INT,@SETMAX VARCHAR(10),@Emp_Id VARCHAR(10)
IF EXISTS(SELECT 1 FROM Mst_Emp)
BEGIN
SELECT @EMP_MAX=RIGHT(MAX(ISNULL(Emp_Id,'')),3) FROM Mst_Emp
SET @MAX=CONVERT(INT,@EMP_MAX)+1;
SET @SETMAX=CONVERT(VARCHAR,@MAX);
IF(LEN(@SETMAX)=1)
SET @Emp_Id='E00'+@SETMAX;
IF(LEN(@SETMAX)=2)
SET @Emp_Id='E0'+@SETMAX;
IF(LEN(@SETMAX)=3)
SET @Emp_Id='E'+@SETMAX;
END
ELSE
BEGIN
SET @Emp_Id=+'E001';
END
SELECT @Emp_Id AS 'MAX_ID'
END --END OF IF
END--END OF PROCEDURE
--EXECUTING THE PROCEDURE
EXEC USP_Mst_Emp 'GET_MAX_ID'
No comments:
Post a Comment