All pastes #374696 Raw Edit

Stuff

public sql v1 · immutable
#374696 ·published 2007-02-27 19:39 UTC
rendered paste body
create procedure set_user_attribute(    @id INT,    @user_id INT,    @attribute_id INT,    @attribute_value varchar(255),    @attribute_value_id INT)BEGIN/*I'm using the @ symbol used by sql server to distinguish variables (this could be different in mysql). @id refers to the id column for user_attribute_value. If that value is -1 this is a new entry. Otherwise I want to update the value. select @@identity returns the new key.*/    if(select @id) = -1       begin          insert into user_attribute_value (user_id, attribute_id, value)          values (@user_id, @attribute_id, @attribute_value)          select @@identity       end    else       begin          update attribute_value             set user_id = @user_id,                 attribute_id = @attribute_id,                 value = @attribute_value          where id = @id          select @id       endENDGO