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

Total Post:24

Points:170
 598  View(s)
Ratings:
Rate this:


  1. Post:280

    Points:1994
    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

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!