Victor_Tlepshev
Victor_Tlepshev

Reputation: 510

INSERT INTO does not work in a stored precedure

I wrote this precedure that checks certain conditions and then runs an INSERT or UPDATE base on the data. However, for some reason the INSERT does not execute.

IF @sid = ''
    BEGIN
        INSERT INTO Book_Art (Sub_ID, Art_IDs, P_ID) VALUES (@Sub_ID,@art_id,@P_ID)
    END
ELSE IF @aids = ''
    BEGIN
        SET @comma = ''
        UPDATE Book_Art SET Art_IDs = + @aids + @comma + @art_id WHERE Sub_ID =  @Sub_ID AND P_ID = @P_ID
    END
ELSE
    BEGIN
        SET @comma = ','
        UPDATE Book_Art SET Art_IDs = + @aids + @comma + @art_id WHERE Sub_ID =  @Sub_ID AND P_ID = @P_ID
    END
END

Upvotes: 0

Views: 47

Answers (1)

Victor_Tlepshev
Victor_Tlepshev

Reputation: 510

Replaced the following:

IF @sid = '' 

With:

IF @sid is null

Upvotes: 1

Related Questions