Function for Generate Auto Unique Id and Procedure for Genereate UserId and Password
-- =============================================
-- Author: <salik ram maurya>
-- =============================================
CREATE PROCEDURE [dbo].[getuniqueid]
(@UniqueNumber Bigint out)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UserUniquid]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].UserUniquid(
[ReceiptNo] [bigint] NOT NULL
) ON [PRIMARY]
END
Declare @Num bigint
Select @Num = MAX([ReceiptNo]) from UserUniquid
IF(@Num IS NULL)
SET @Num = 1
ELSE
SET @Num = @Num+1;
INSERT INTO UserUniquid ([ReceiptNo]) VALUES (@Num)
--Declare @Session char(9)
--Select @Session=Convert(Varchar,(StartsFrom-2000))+'-'+Convert(Varchar,(EndsOn-2000)) From SessionMaster Where SessionID =@SessionID
--Declare @ReceiptNo Varchar(500)
--Select @ReceiptNo =@Num --'india'+RIGHT(REPLICATE('0',5)+CONVERT(varchar(8),@NUM),8)
Set @UniqueNumber=@Num
END
---
CREATE proc [user_registration]
@Fname varchar(50),
@Mname varchar(50),
@Lname varchar(50),
@Dob datetime,
@Contactno bigint,
@EmailID varchar(100),
@Empcode varchar(50)
as
begin
declare @userid varchar(50),@Password varchar(50)
SELECT @userid =LTRIM(@Fname)+''+LOWER(@Lname)--+ LEFT(NewID(),2)
DECLARE @Upper INT; DECLARE @Lower INT
SET @Lower = 1111
SET @Upper = 9999
SELECT @Password =CONVERT(nvarchar(50), year('1985'))+''+CONVERT(nvarchar(50), ROUND(((@Upper - @Lower -1) * RAND() + @Lower), 0) )
if not exists(Select 1 From Registration Where UserId=@userid and Empcode=@Empcode And IsActive=1)
begin
insert into Registration(Empcode,Firstname,Middlename,LastName,Dob,ContactNo,EmailId,UserId,Password,EnteredOn)
values(@Empcode,@Fname,@Mname,@Lname,@Dob,@Contactno,@EmailID,@userid,@Password,GETDATE())
select IDENT_CURRENT('Registration')
end
else
begin
Declare @Unique Bigint
Exec getuniqueid @Unique out
insert into Registration(Empcode,Firstname,Middlename,LastName,Dob,ContactNo,EmailId,UserId,Password,EnteredOn)
values(@Empcode,@Fname,@Mname,@Lname,@Dob,@Contactno,@EmailID,@userid+Convert(varchar(4000),@Unique),@Password,GETDATE())
select IDENT_CURRENT('Registration')
end
end
-- =============================================
-- Author: <salik ram maurya>
-- =============================================
CREATE PROCEDURE [dbo].[getuniqueid]
(@UniqueNumber Bigint out)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UserUniquid]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].UserUniquid(
[ReceiptNo] [bigint] NOT NULL
) ON [PRIMARY]
END
Declare @Num bigint
Select @Num = MAX([ReceiptNo]) from UserUniquid
IF(@Num IS NULL)
SET @Num = 1
ELSE
SET @Num = @Num+1;
INSERT INTO UserUniquid ([ReceiptNo]) VALUES (@Num)
--Declare @Session char(9)
--Select @Session=Convert(Varchar,(StartsFrom-2000))+'-'+Convert(Varchar,(EndsOn-2000)) From SessionMaster Where SessionID =@SessionID
--Declare @ReceiptNo Varchar(500)
--Select @ReceiptNo =@Num --'india'+RIGHT(REPLICATE('0',5)+CONVERT(varchar(8),@NUM),8)
Set @UniqueNumber=@Num
END
---
CREATE proc [user_registration]
@Fname varchar(50),
@Mname varchar(50),
@Lname varchar(50),
@Dob datetime,
@Contactno bigint,
@EmailID varchar(100),
@Empcode varchar(50)
as
begin
declare @userid varchar(50),@Password varchar(50)
SELECT @userid =LTRIM(@Fname)+''+LOWER(@Lname)--+ LEFT(NewID(),2)
DECLARE @Upper INT; DECLARE @Lower INT
SET @Lower = 1111
SET @Upper = 9999
SELECT @Password =CONVERT(nvarchar(50), year('1985'))+''+CONVERT(nvarchar(50), ROUND(((@Upper - @Lower -1) * RAND() + @Lower), 0) )
if not exists(Select 1 From Registration Where UserId=@userid and Empcode=@Empcode And IsActive=1)
begin
insert into Registration(Empcode,Firstname,Middlename,LastName,Dob,ContactNo,EmailId,UserId,Password,EnteredOn)
values(@Empcode,@Fname,@Mname,@Lname,@Dob,@Contactno,@EmailID,@userid,@Password,GETDATE())
select IDENT_CURRENT('Registration')
end
else
begin
Declare @Unique Bigint
Exec getuniqueid @Unique out
insert into Registration(Empcode,Firstname,Middlename,LastName,Dob,ContactNo,EmailId,UserId,Password,EnteredOn)
values(@Empcode,@Fname,@Mname,@Lname,@Dob,@Contactno,@EmailID,@userid+Convert(varchar(4000),@Unique),@Password,GETDATE())
select IDENT_CURRENT('Registration')
end
end
No comments:
Post a Comment