Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
Node is saved as draft in My Content >> Draft
  • Use of Scope Identity in SQL

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 198
    Comment on it

    We need the latest record that is inserted or updated . For doing that we need to find the latest row that can be done with the help of scope identity

    ALTER  procedure [dbo].[sp_AddEmployee]
    (
    @EmpName varchar(80),
    @EmpDesgnationId int,
    @EmpDob date,
    @EmpSal money,
    @EmpDoj date,
    @EmpEmail varchar(100),
    @EmpManagerId int ,
    @EmpLogUserName varchar(100),
    @EmpLogUserPassword varchar(100)
    
    )
    as
    begin
    declare @EmpID int
    insert into dbo.EmployeeDetails(EmployeeName,EmployeeDesignationId,EmployeeDob,EmployeeSal,EmployeeDoj,EmployeeEmail,EmployeeManagerId) values (@EmpName,@EmpDesgnationId,@EmpDob,@EmpSal,@EmpDoj,@EmpEmail,@EmpManagerId)
    set @EmpID=SCOPE_IDENTITY()
    insert into dbo.EmployeeLogin (EmployeeId,EmployeeLoginUserName,EmployeeLoginPassword) values (@EmpID,@EmpLogUserName,@EmpLogUserPassword)
    end

    This will return the latest employee inserted.

    SQL Server

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: