Stored Proc help, prevent insert.

  • I have a stored proc that I want to prevent the insert to happen if the UserID and InvitedUserID are the same

    ALTER PROCEDURE [dbo].[cs_njection_invitation_accepted]

    @user-id int,

    @SettingsID

    int,

    @InvitedUserID

    int

    AS

    insert

    into cs_njection_invite_points (UserID, SettingsID, InvitedUserID)

    values

    ( @user-id, @SettingsID, @InvitedUserID)

    Any ideas?

  • it's easier than you thought.

    several ways.

    add a constraint to the table where UserID <> @InvitedUserid.

    Use the If example below.

    ALTER

    PROCEDURE [dbo].[cs_njection_invitation_accepted]

    @user-id int,

    @SettingsID

    int,

    @InvitedUserID

    int

    AS

    IF @user-id <> @InvitedUserID

    begin

    insert

    into cs_njection_invite_points (UserID, SettingsID, InvitedUserID)

    values

    ( @user-id, @SettingsID, @InvitedUserID)

    end

     

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply