I am trying to create procedure, which is generating an error stating
An explicit value for the identity column in table tblRegisterUser
can only be specified when a column list is used and IDENTITY_INSERT is ON
.
I tried to surround insert statement with INDENTITY_INSERT to ON
,but that too doesn't work. am I missing anything or is it an error with the sub query which i included?
Following is the stored procedure
CREATE PROCEDURE dbo.spInsertUserRegister
(
@FirstName nvarchar(50),
@LastName nvarchar(50),
@Username nvarchar(50),
@Password nvarchar(50),
@Designation nvarchar(50),
@Department nvarchar(50),
@IsAdmin bit
)
AS
BEGIN
INSERT INTO tblRegisterUser Values
(
@FirstName, @LastName, @Username, @Password,@Designation,@Department,@IsAdmin
)
DECLARE @UID INT
SET @UID = @@IDENTITY
INSERT INTO tblLogin(Username,Password,UID,IsAdmin)
Values(@Username, @Password, @UID,(SELECT IsAdmin FROM tblRegisterUser WHERE Username=@Username AND Password=@Password))
END