I have a code like this:

```
IF EXISTS (SELECT * FROM table WHERE id = @id)
BEGIN
    UPDATE table
    SET stock = stock + @stock
    WHERE id = @id
END
ELSE
BEGIN
    INSERT INTO [table] ([id], [name], [stock])
    VALUES (@id, @name, @stock)
END

```

But, this code isn't working and I am unable to find the root cause for the same. Can someone please help me?