How to Create a Common Stored Procedure For Insert Update and Delete ?

Total Post:49

Points:345
 640  View(s)
Ratings:
Rate this:


  1. Post:281

    Points:2003
    Re: How to Create a Common Stored Procedure For Insert Update and Delete ?

    CREATE PROCEDURE MasterInsertUpdateDelete 
    
    (

    @ContactID int,
    @Name varchar(50),
    @Mobile varchar(50),
    @Address varchar(250),
    @Query int
    )
    AS
    BEGIN
    IF(@Query = 1)
    BEGIN
    Insert into Contact
    (
    Name ,
    Mobile ,
    Address
    )
    values
    (
    @Name ,
    @Mobile ,
    @Address
    )
    IF(@@ROWCOUNT > 0)
    Begin
    Select 'Insert'
    End
    End
    IF(@Query = 2)
    Begin
    Update Contact
    set
    Name =@Name ,
    Mobile =@Mobile ,
    Address = @Address
    where ContactID =@ContactID
    Select 'Update'
    End

    IF(@Query = 3)
    Begin
    Delete from Contact where ContactID =@ContactID
    Select 'Deleted'
    End

    IF(@Query = 4)
    Begin
    Select * from Contact
    End
    End

    IF(@Query = 5)
    Begin
    Select * from Contact where ContactID =@ContactID
    End

    How to Create a Common Stored Procedure For Insert Update and Delete ?

Answer