Friday, April 27, 2012

Insert ,Update and return id in One Stored Procedure


USE [Surgere1]
GO
/****** Object:  StoredProcedure [dbo].[dbo.facility_lane_addUpdate]    Script Date: 04/27/2012 12:05:22 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER Procedure [dbo].[dbo.facility_lane_addUpdate]
(
        @facility_lane_ID  bigint output  ,
        @facility_ID  bigint =NULL ,
        @door_no  varchar (20)  =NULL ,
        @door_name  varchar (50)  =NULL ,
        @door_order  bigint =NULL ,
        @IPReader  varchar (50)  =NULL ,
        @Created_id  bigint =NULL ,
        @Created_dt  datetime =NULL ,
        @Update_ID  bigint =NULL ,
        @Update_dt  datetime =NULL

)
AS
Begin
SET NOCOUNT ON;
             If @facility_lane_ID<1
             Begin
                   Insert into dbo.facility_lane
                   (
                                         facility_ID ,
                                         door_no ,
                                         door_name ,
                                         door_order ,
                                         IPReader ,
                                         Created_id ,
                                         Created_dt ,
                                         Update_ID ,
                                         Update_dt

                   )
                   Values
                   (
                                         @facility_ID ,
                                         @door_no ,
                                         @door_name ,
                                         @door_order ,
                                         @IPReader ,
                                         @Created_id ,
                                         @Created_dt ,
                                         @Update_ID ,
                                         @Update_dt

                   );
Set @facility_lane_ID=SCOPE_IDENTITY();
                    END
                     Else
                    BEGIN
Update dbo.facility_lane
set
                                         facility_ID = @facility_ID ,
                                         door_no = @door_no ,
                                         door_name = @door_name ,
                                         door_order = @door_order ,
                                         IPReader = @IPReader ,
                                         Created_id = @Created_id ,
                                         Created_dt = @Created_dt ,
                                         Update_ID = @Update_ID ,
                                         Update_dt = @Update_dt

Where facility_lane_ID=@facility_lane_ID;
            END
Return @facility_lane_ID
END

No comments:

Using Authorization with Swagger in ASP.NET Core

 Create Solution like below LoginModel.cs using System.ComponentModel.DataAnnotations; namespace UsingAuthorizationWithSwagger.Models {     ...